按照 ISO-8601 标准,一周的开始时间是星期一,一年的第一周包含 1 月 4 日。因此,一月初的日期有时可能会位于上一个历年的第 52 周或第 53 周。例如:
=> SELECT YEAR_ISO('01-01-2016'::DATE), WEEK_ISO('01-01-2016'), DAYOFWEEK_ISO('01-01-2016');
YEAR_ISO | WEEK_ISO | DAYOFWEEK_ISO
----------+----------+---------------
2015 | 53 | 5
(1 row)
提取日期值:
SELECT DATE_PART('DAY', TIMESTAMP '2009-02-24 20:38:40') "Day";
-----
(1 row)
提取月份值:
SELECT DATE_PART('MONTH', '2009-02-24 20:38:40'::TIMESTAMP) "Month";
Month
-------
(1 row)
提取年份值:
SELECT DATE_PART('YEAR', '2009-02-24 20:38:40'::TIMESTAMP) "Year";
------
(1 row)
提取小时:
SELECT DATE_PART('HOUR', '2009-02-24 20:38:40'::TIMESTAMP) "Hour";
------
(1 row)
提取分钟:
SELECT DATE_PART('MINUTES', '2009-02-24 20:38:40'::TIMESTAMP) "Minutes";
Minutes
---------
(1 row)
提取季度日期 (DOQ):
SELECT DATE_PART('DOQ', '2009-02-24 20:38:40'::TIMESTAMP) "DOQ";
-----
(1 row)
TO_CHAR