【发布时间】:2020-01-23 08:28:30
【问题描述】:
我的表 firstdate 和 lastdate 中有 2 列
第一个日期例如是今天 (2020-1-22)。 lastday 是加 1 年减去 1 天 (2021-1-21)。
所以我的插入脚本是这样的:
INSERT INTO <table> (firstdate, lastdate)
VALUES (current_date, current_date + interval '1 year -1 day')
好的,到目前为止一切顺利。现在我想推断它以再次使用它。
我的问题是基于这两个日期。如何从这两个日期再次返回间隔?
当我使用 Postgres 函数 age 时,我得到以下结果:0 years 11 months 30 days。
我无法使用此区间进行正确计算,因为区间 0 years 11 months 30 days 与区间 1 years -1 days 不同。
所以我需要以某种方式返回1 years -1 days
【问题讨论】:
-
如果您想知道使用了哪个区间(在插入中),那么也要存储区间。
标签: postgresql