Postgresql 時間加減運算


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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM