PostgreSQL date addition and subtraction

In PostgreSQL, you can directly add and subtract time:,
SELECT now()::timestamp + '1 year'; -- add 1 year to the current time
SELECT now()::timestamp + '1 month'; --Add one month to the current time
SELECT now()::timestamp + '1 day'; -- current time plus one day
SELECT now()::timestamp + '1 hour'; -- add one hour to the current time
SELECT now()::timestamp + '1 min'; -- add one minute to the current time
SELECT now()::timestamp + '1 sec'; -- add one second
select now()::timestamp + '1 year 1 month 1 day 1 hour 1 min 1 sec'; -- add 1 year 1 month 1 day 1 hour 1 minute 1 second
SELECT now()::timestamp + (col || ' day')::interval FROM table -- convert the col field to days and add them together

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326146105&siteId=291194637