我有一个表格,其列表的时间戳类型没有时区.
我想选择具有mmm yyyy格式的列- 例如,"2011年3月".如何格式化它?我试过了:
select cast(now() as date)
Run Code Online (Sandbox Code Playgroud)
但它给了我不正确的格式.
小智 21
DateAndTime重新格式化:
SELECT *, to_char( last_update, 'DD-MON-YYYY') as re_format from actor;
Run Code Online (Sandbox Code Playgroud)
DEMO:
Yav*_*sov 12
您需要使用日期格式化函数,例如to_char http://www.postgresql.org/docs/current/static/functions-formatting.html
Elm*_*zad 11
我认为在 Postgres 中,如果你愿意,你可以使用格式 dd/mm/yyyy
TO_CHAR(submit_time, 'DD/MM/YYYY') as submit_date
Run Code Online (Sandbox Code Playgroud)
小智 9
您可以将选择查询编写为,
select * from table_name where to_char(date_time_column, 'YYYY-MM') = '2011-03';
Run Code Online (Sandbox Code Playgroud)