【发布时间】:2014-12-30 17:13:18
【问题描述】:
我想知道是否有其他人遇到过或知道有关它的信息。
今天是 2014 年 11 月 3 日,如果我检查 2013 年 11 月 5 日是否在去年之内,我会根据我检查的方式得到不同的答案:1 年与 365 天
select now() - '20131105' as diff,
case when now() - '20131105' <= '1 year' then 'within year' else 'not within year' end as yr_check,
case when now() - '20131105' <= '365 days' then 'within 365 days' else 'not within 365 days' end as day_check
2014-11-03 16:27:38.39669-06; 363 days 16:27:38.39669; not within year; within 365 days
查询时好像是 11 月 9 日,没关系
select now() as right_now, now() - '20131109' as diff,
case when now() - '20131109' <= '1 year' then 'within year' else 'not within year' end as yr_check,
case when now() - '20131109' <= '365 days' then 'within 365 days' else 'not within 365 days' end as day_check
2014-11-03 16:31:12.464469-06; 359 days 16:31:12.464469; within year; within 365 days
有人对此有想法吗?或者关于日期算术有什么有趣的地方吗?
postgres 版本是 9.2.4
【问题讨论】:
-
将
now()替换为能够重现该问题的时间戳对于那些在您编写该问题的同一天没有看到此问题的人会有所帮助。
标签: postgresql datediff