In PostgreSQL, you can use the INTERVAL keyword along with the DATE_ADD() function to add or subtract months from a date. Here's how you can use it:
SELECT '2022-01-15' + INTERVAL '3 months' AS new_date;
This query will add 3 months to the date '2022-01-15', resulting in the date '2022-04-15'.
Similarly, you can subtract months by using a negative interval:
SELECT '2022-01-15' + INTERVAL '-2 months' AS new_date;
This query will subtract 2 months from the date '2022-01-15', resulting in the date '2021-11-15'.
So, in PostgreSQL, you use the + operator along with the INTERVAL keyword to add or subtract months from a date.
No comments:
Post a Comment