Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Friday, 16 February 2024

ADD MONTHS in MARIADB

In MariaDB, you can use the DATE_ADD() function to add or subtract months from a date. Here's how you can use it:

SELECT DATE_ADD('2022-01-15', INTERVAL 3 MONTH) 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 DATE_ADD('2022-01-15', INTERVAL -2 MONTH) AS new_date;

This query will subtract 2 months from the date '2022-01-15', resulting in the date '2021-11-15'.

So, in MariaDB, you use the DATE_ADD() function with the INTERVAL keyword to add or subtract months from a date.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.