PostgreSQL 13に週の加算のサンプル

書式
週の加算
日付 + cast( 'xx weeks’ as INTERVAL )

環境
Windows10 64 bit
PostgreSQL 13.2

使用例
1.現在時刻に8週加えます

postgres=# select now() + cast('8 weeks' as INTERVAL) result;
            result
-------------------------------
 2022-03-05 22:00:39.215478+09
(1 行)

2.「2022/1/2」に8週加えます

postgres=# select cast('2022/1/2' as date) + cast('8 weeks' as INTERVAL) result;
       result
---------------------
 2022-02-27 00:00:00
(1 行)

3.「2022/1/2 18:00:12」に8週加えます

postgres=# select cast('20220102 18:00:12' as timestamp) + cast('8 weeks' as INTERVAL) result;
       result
---------------------
 2022-02-27 18:00:12
(1 行)

 

PostgreSQL

Posted by arkgame