[英]Date from N days ago
Is there less verbose way to get date
N days ago? N天前有没有那么冗长的date
方法?
select ('today'::date -'20 days'::interval)::date;
date
------------
2018-07-10
https://www.postgresql.org/docs/current/static/functions-datetime.html has example (the very first date
+ integer
, so you can omit interval
and date
casts: https://www.postgresql.org/docs/current/static/functions-datetime.html包含示例(第一个date
+ integer
,因此您可以省略interval
和date
强制转换:
db=# select current_date -20;
?column?
------------
2018-07-10
(1 row)
I think the "correct" way in Postgres is: 我认为Postgres中的“正确”方法是:
select current_date - interval '20 day'
Although you can use - 20
as a shorthand for - interval '20 day'
, I strongly recommend that you use the full interval
form for clarity. 尽管您可以使用- 20
作为“ - interval '20 day'
的简写,但为清晰起见,我强烈建议您使用完整interval
表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.