Is there less verbose way to get date
N days ago?
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:
db=# select current_date -20;
?column?
------------
2018-07-10
(1 row)
I think the "correct" way in Postgres is:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.