SQL postgresql 中 mmm yyyy 格式的日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7415077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:06:56  来源:igfitidea点击:

Date in mmm yyyy format in postgresql

sqlpostgresql

提问by Deepak Kumar

I have a table with a column of type timestamp without time zone.

我有一个没有时区的时间戳类型列的表。

I want to select that column with the mmm yyyyformat – for example, “Mar 2011”. How to format it that way? I tried:

我想用mmm yyyy格式选择该列- 例如,“2011 年 3 月”。如何以这种方式格式化?我试过:

select cast(now() as date)

but it is giving me the incorrect format.

但它给了我不正确的格式。

回答by Mohamed Saligh

SELECT TO_CHAR(NOW(), 'Mon YYYY');

SELECT TO_CHAR(NOW(), 'Mon YYYY');

回答by Ram Pukar

DateAndTime Reformat:

日期和时间重新格式化:

SELECT *, to_char( last_update, 'DD-MON-YYYY') as re_format from actor;

DEMO:

演示:

enter image description here

在此处输入图片说明

回答by Yavor Shahpasov

You need to use a date formatting function for example to_char http://www.postgresql.org/docs/current/static/functions-formatting.html

您需要使用日期格式功能,例如 to_char http://www.postgresql.org/docs/current/static/functions-formatting.html

回答by Rohit Sonawane

You can write your select query as,

您可以将选择查询编写为,

select * from table_name where to_char(date_time_column, 'YYYY-MM')  = '2011-03';

回答by Elmira Behzad

I think in Postgres you can play with formats for example if you want dd/mm/yyyy

我认为在 Postgres 中,如果你愿意,你可以使用格式 dd/mm/yyyy

TO_CHAR(submit_time, 'DD/MM/YYYY') as submit_date