MySQL 与postgreSQL日期加减

MySQL 日期加减

select adddate(now(),1); --1天

select adddate(now(), interval 1 day); --1天

select adddate(now(), interval 1 hour); --1小时

select adddate(now(), interval 1 minute); --1分钟

select adddate(now(), interval 1 second); --1秒

select adddate(now(), interval 1 microsecond); --1毫秒

select adddate(now(), interval 1 week); --1周

select adddate(now(), interval 1 month); --1月

select adddate(now(), interval 1 quarter); --1季

select adddate(now(), interval 1 year); --1

postgreSQL日期加减

SELECT now()::timestamp + '1 year';  --当前时间加1年

SELECT now()::timestamp + '1 month';  --当前时间加一个月

SELECT now()::timestamp + '1 day';  --当前时间加一天

SELECT now()::timestamp + '1 hour';  --当前时间加一个小时

SELECT now()::timestamp + '1 min';  --当前时间加一分钟

SELECT now()::timestamp + '1 sec';  --加一秒钟

select now()::timestamp + '1 year 1 month 1 day 1 hour 1 min 1 sec';  --111111秒

SELECT now()::timestamp + (col || ' day')::interval FROM table --把col字段转换成天 然后相加

猜你喜欢

转载自blog.csdn.net/weixin_46099269/article/details/113125569