带有时区的时间戳是这个- 2020-05-31T10:05:07Z
尽管参考了官方文档,但这仍然行不通。我需要提取2020年5月或单独的月份和年份以与2020年5月进行比较
SELECT date_trunc('hour', TIMESTAMP '2020-05-31T10:05:07Z')
SELECT date_part('day', TIMESTAMP '2020-05-31T10:05:07Z');
如果要检查时间戳记值是否为“ 2020年5月”,则有不同的选择。
to_char(the_value, 'yyyy-mm') = '2020-05'
或者
extract(month from the_value) = 5
and extract(year from the_value) = 2020
或者
(extract(month from the_value), extract(year from the_value)) = (5, 2020)
extract()
并且date_part()
是同一件事-但我更喜欢标准兼容extract()
版本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句