postgresql中的DATE_FORMAT

Sat*_*ish 9 mysql database postgresql postgresql-9.0 postgresql-9.1

我在postgresql中工作,我需要在查询本身转换日期格式,在mysql中有调用选项DATE_FORMAT,我可以使用这样的查询:

Select DATE_FORMAT(date_time, '%b %e, %Y, %T') from table_name
Run Code Online (Sandbox Code Playgroud)

postgresql有什么选择吗?如果有的话请告诉我?

Amr*_*ita 24

如果我修改你的

Select DATE_FORMAT(date_time, '%b %e, %Y, %T') from table_name
Run Code Online (Sandbox Code Playgroud)

Select DATE_FORMAT(now(), '%b %e, %Y, %T')
Run Code Online (Sandbox Code Playgroud)

它会回来Aug 21, 2012, 16:51:30.

你可以在Postgresql中做同样的事情:

Select to_char(now(), 'Mon-dd-YYYY,HH24:MM:SS')
Run Code Online (Sandbox Code Playgroud)

会回报你 Aug-21-2012,16:08:08

希望你的问题得到解决.


a_h*_*ame 12

使用 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;
Run Code Online (Sandbox Code Playgroud)


Moy*_*ari 8

尝试这个

SELECT to_char(date_time, 'dd.mm.YYYY') from table_name
Run Code Online (Sandbox Code Playgroud)


lon*_*ong 5

to_char,例如:

to_char(creation_date, 'FMDD.MM.YYYY, HH24:MI:SS') AS creation_date_f
Run Code Online (Sandbox Code Playgroud)