mysqldatabasepostgresqlpostgresql-9.1postgresql-9.0

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?


Solution

  • 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:mi:ss')
    

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

    Hope your problem is sort out.