postgreSQL日期加减

来源:互联网 发布:哪个加油软件好 编辑:程序博客网 时间:2024/06/16 00:56

在PostgreSQL中可以直接对时间进行加减运算:SELECT now()::timestamp + '1 year';

 --当前时间加1年

SELECT now()::timestamp + '1 year';  

'SELECT create_time + '1 year' from table;  


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

SELECT create_time + '1month' from table;

 
--加1年1月1天1时1分1秒
select now()::timestamp + '1 year 1 month 1 day 1 hour 1 min 1 sec';  

selectcreate_time + '1 year 1 month 1 day 1 hour 1 min 1 sec';   

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