PostgreSQL 13に月の加算のサンプル
環境
Windows10 64 bit
PostgreSQL 13.2
書式
月の加算
日付 + cast( 'xx months’ as INTERVAL )
使用例
1.現在時刻に3ヶ月加えます
postgres=# select now() + cast('3 months' as INTERVAL) result; result ------------------------------- 2022-04-08 22:09:19.013945+09 (1 行)
2.「2022/1/2」に3ヶ月加えます
postgres=# select cast('2022/1/2' as date) + cast('3 months' as INTERVAL) result; result --------------------- 2022-04-02 00:00:00 (1 行)
3.「2022/1/2 18:00:12」に3ヶ月加えます
postgres=# select cast('20220102 18:00:12' as timestamp) + cast('3 months' as INTERVAL) result; result --------------------- 2022-04-02 18:00:12 (1 行)