MySQL DATE_ADD() Function
In MySQL, the DATE_ADD() function adds the specified interval to the specified date/time and returns the result.
DATE_ADD() Syntax
Here is the syntax of MySQL DATE_ADD() function:
DATE_ADD(date, INTERVAL value unit)
Parameters
date- Required. A data or datetime value or expression.
value- Required. A date/time interval. Both positive and negative numbers are allowed.
unit- Required. The unit of the date/time interval.
The unit of the data/time interval can be one of the following values:
MICROSECONDSECONDMINUTEHOURDAYWEEKMONTHQUARTERYEARSECOND_MICROSECONDMINUTE_MICROSECONDMINUTE_SECONDHOUR_MICROSECONDHOUR_SECONDHOUR_MINUTEDAY_MICROSECONDDAY_SECONDDAY_MINUTEDAY_HOURYEAR_MONTH
Return value
The DATE_ADD() function adds the specified date/time interval to the specified data or datetime value and returns the result. The result’s date type is determined by the parameters:
- If
dateis aDATEvalue andunitisYEAR,MONTHorDAY, it returns aDATEvalue. - If
dateis aDATEvalue andunitisHOURS,MINUTESorSECONDS, it returns aDATETIMEvalue. - If
dateis aDATETIMEvalue, it returns aDATETIMEvalue. - If
dateis aTIMEvalue andunitisYEAR,MONTHorDAY, it returns aDATETIMEvalue. - If
dateis aTIMEvalue and the computation involves only theHOURS,MINUTESandSECONDSparts , it returns aTIMEvalue. (MySQL 8.0.28 and later) - Otherwise it returns a string value.
DATE_ADD() Examples
Here are some examples of the DATE_ADD() function.
Example 1
SELECT
DATE_ADD('2020-06-10', INTERVAL 10 DAY),
DATE_ADD('2020-06-10', INTERVAL 10 HOUR)\G
DATE_ADD('2020-06-10', INTERVAL 10 DAY): 2020-06-20
DATE_ADD('2020-06-10', INTERVAL 10 HOUR): 2020-06-10 10:00:00Example 2
SELECT
DATE_ADD('2020-06-10 10:00:00', INTERVAL 10 HOUR),
DATE_ADD('2020-06-10 10:00:00', INTERVAL 10 MINUTE)\G
DATE_ADD('2020-06-10 10:00:00', INTERVAL 10 HOUR): 2020-06-10 20:00:00
DATE_ADD('2020-06-10 10:00:00', INTERVAL 10 MINUTE): 2020-06-10 10:10:00Example 3
SELECT
DATE_ADD(CURDATE(), INTERVAL 10 HOUR),
DATE_ADD(NOW(), INTERVAL 10 MINUTE)\G
DATE_ADD(CURDATE(), INTERVAL 10 HOUR): 2022-04-11 10:00:00
DATE_ADD(NOW(), INTERVAL 10 MINUTE): 2022-04-11 08:35:42Here, we used the CURDATE() function to get the current date and used the NOW() function to get the current datetime.