MySql Date Add Subtract

To add or subtract dates through MySql, here are both of the examples, where you will find how to add and how to subtract a date, from a given date, in MySql:

MySql Add Date

To add MySql date through a query, like if you want to get a date, for example:

MySql Add Day

If you want to find out what date will it be after two days, write the following query:
SELECT DATE_ADD(NOW(), INTERVAL 2 DAY)

MySql Add Month

If you want to find out what date will it be after one month, write the following query:
SELECT DATE_ADD(NOW(), INTERVAL 1 MONTH)

MySql Add Year

Or if you want to find out what date will it be after one year, write the following query:
SELECT DATE_ADD(NOW(), INTERVAL 1 YEAR)

MySql Subtract Date

To subtract MySql date through a query, like if you want to get a date, for example:

MySql Subtract Day

If you want to find out what date will it be after two days, write the following query:
SELECT DATE_SUB(NOW(), INTERVAL 2 DAY)

MySql Subtract Month

If you want to find out what date will it be after one month, write the following query:
SELECT DATE_SUB(NOW(), INTERVAL 1 MONTH)

MySql Subtract Year

Or if you want to find out what date will it be after one year, write the following query:
SELECT DATE_SUB(NOW(), INTERVAL 1 YEAR)

Also note that, if you want to get only date, and not the hours, minutes and seconds, then simple add the DATE() function at the start of the query, like:

SELECT DATE(DATE_SUB(NOW(), INTERVAL 2 DAY))

Uncategorised

Leave a Reply

Your email address will not be published. Required fields are marked *