now()::timestamp(0)精確到秒
加法:
SELECT now()::timestamp(0) + '1 year'; --當前時間加1年 SELECT now()::timestamp(0) + '1 month'; --當前時間加一個月 SELECT now()::timestamp(0) + '1 day'; --當前時間加一天 SELECT now()::timestamp(0) + '1 hour'; --當前時間加一個小時 SELECT now()::timestamp(0) + '1 min'; --當前時間加一分鍾 SELECT now()::timestamp(0) + '1 sec'; --加一秒鍾 select now()::timestamp(0) + '1 year 1 month 1 day 1 hour 1 min 1 sec'; --加1年1月1天1時1分1秒 SELECT now()::timestamp(0) + (col || ' day')::interval FROM table --把col字段轉換成天 然后相加
減法:
需要反向操作
select CURRENT_TIMESTAMP::TIMESTAMP + '-5 day'
整理自:https://blog.csdn.net/qq_41483673/article/details/103819407
(0)