DATE_FORMAT in postgresql

I work in postgresql, and I need to convert the date format in the query itself, in mysql there is an option called DATE_FORMAT, and I can use this query:

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

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

+5
source share
4 answers

If i change your

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

to

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

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

You can do the same in Postgresql:

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

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

I hope your problem is sorted out.

+22
source

try it

SELECT to_char(date_time, 'dd.mm.YYYY') from table_name
+3
source

to_char():

http://www.postgresql.org/docs/current/static/functions-formatting.html

, '%b %e, %Y, %T' ( ), Postgres.

ANSI:

select to_char(date_time, 'yyyy-mm-dd hh24:mi:ss')
from table_name;
+3

to_char, :

to_char(creation_date, 'FMDD.MM.YYYY, HH24:MI:SS') AS creation_date_f
+2
source

All Articles