Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DATE_FORMAT in postgresql

I'm working in postgresql and I need to convert the date format in query itself, in mysql there is option called DATE_FORMAT and I can use a query like this:

Select DATE_FORMAT(date_time, '%b %e, %Y, %T') from table_name

is there any option in postgresql? Please let me know if any?

like image 577
Sathish Avatar asked Aug 21 '12 10:08

Sathish


1 Answers

If I modify your

Select DATE_FORMAT(date_time, '%b %e, %Y, %T') from table_name

to

Select DATE_FORMAT(now(), '%b %e, %Y, %T')

it will return Aug 21, 2012, 16:51:30.

You can do the same thing in Postgresql:

Select to_char(now(), 'Mon-dd-YYYY,HH24:MM:SS')

will return you Aug-21-2012,16:08:08

Hope your problem is sort out.

like image 74
Amrita Avatar answered Oct 14 '22 21:10

Amrita