如何在不使用to_char()函数的情况下从PostgreSQL中的日期中提取年份和月份? [英] How to extract year and month from date in PostgreSQL without using to_char() function?
本文介绍了如何在不使用to_char()函数的情况下从PostgreSQL中的日期中提取年份和月份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要选择sql:
从表组中按年-月选择年-月并按日期排序
,其中
year-month-格式为日期 1978-01, 1923-12。
选择工作的to_char ,而不是正确的顺序:
I want to select sql:
SELECT "year-month" from table group by "year-month" AND order by date
, where
year-month - format for date "1978-01","1923-12".
select to_char of couse work, but not "right" order:
to_char(timestamp_column, 'YYYY-MM')
推荐答案
date_part(text, timestamp)
例如
date_part('month', timestamp '2001-02-16 20:38:40'),
date_part('year', timestamp '2001-02-16 20:38:40')
http://www.postgresql.org/docs/8.0/interactive/functions-datetime.html
这篇关于如何在不使用to_char()函数的情况下从PostgreSQL中的日期中提取年份和月份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文