Extract Month From Date Field

岁酱吖の 提交于 2020-02-03 08:13:35

问题


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

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


回答1:


You may find this useful

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




回答2:


A simpler version.

to_char(input, 'Month') AS Month

Source : Data Type Formatting Functions



来源:https://stackoverflow.com/questions/36869703/extract-month-from-date-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!