postgresql 从日期字段中提取月份
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36869703/
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
Extract Month From Date Field
提问by BobJonesGodfrey LovesToEatSush
I have a date field in a postgresql database (field name is input) how can I extract the month only from the date field? I used the syntax below, but I want it to show the actual month name, not a numeric value for the month
我在 postgresql 数据库中有一个日期字段(输入字段名称)如何仅从日期字段中提取月份?我使用了下面的语法,但我希望它显示实际的月份名称,而不是月份的数值
EXTRACT(MONTH FROM input) AS "Month"
So if the date in the field input was 04/26/2016 this syntax returns 4, how could I alter this to return April
因此,如果字段输入中的日期是 2016 年 4 月 26 日,则此语法返回 4,我该如何更改它以返回四月
采纳答案by pnorton
You may find this useful
你可能会发现这很有用
SELECT to_char(to_timestamp (date_part('month', timestamp '2016-04-26 20:38:40')::text, 'MM'), 'Month')
SELECT to_char(to_timestamp (date_part('month', timestamp '2016-04-26 20:38:40')::text, 'MM'), 'Month')
All the best
一切顺利
Ref Postgresql (Current) Section 9.9. Date/Time Functions and Operators
回答by Ram
A simpler version.
一个更简单的版本。
to_char(input, 'Month') AS Month
to_char(input, 'Month') AS Month
Source : Data Type Formatting Functions
来源:数据类型格式化函数