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)
 posted on 2020-10-17 15:08  xibuhaohao  阅读(7691)  评论(0编辑  收藏  举报