MySQL DATE_ADD

Syntax :

DATE_ADD(date, INTERVAL value addunit)

DATE_ADD() function is used to add a specified time or date interval to a specified date and then return the date.

Parameters of MySQL DATE_ADD() function : 

date : The date is to which the interval should be added.

value : The value is the date or time interval to add. This value can be both positive and negative.

addunit : The addunit is the type of interval to add such as SECOND, MINUTE, HOUR, DAY, YEAR, MONTH etc.

 

unit Value Expected expr Format
MICROSECOND MICROSECONDS
SECOND SECONDS
MINUTE MINUTES
HOUR HOURS
DAY DAYS
WEEK WEEKS
MONTH MONTHS
QUARTER QUARTERS
YEAR YEARS
SECOND_MICROSECOND 'SECONDS.MICROSECONDS'
MINUTE_MICROSECOND 'MINUTES.MICROSECONDS'
MINUTE_SECOND 'MINUTES:SECONDS'
HOUR_MICROSECOND 'HOURS.MICROSECONDS'
HOUR_SECOND 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE 'HOURS:MINUTES'
DAY_MICROSECOND 'DAYS.MICROSECONDS'
DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE 'DAYS HOURS:MINUTES'
DAY_HOUR 'DAYS HOURS'
YEAR_MONTH 'YEARS-MONTHS'

Examples of DATE_ADD() function

Example 1 : Add 20 days to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL 20 DAY) as date;

// output : 2022-06-04 09:25:18

 

Example 2 : Add 11 months to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL 11 MONTH) as date;

// output : 2023-04-15 09:25:18

 

Example 3 : Subtract 2 months to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL -2 MONTH) as date;

// output : 2022-03-15 09:25:18

 

Example 4 : Add 1 year to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL 1 YEAR) as date;

// output : 2023-05-15 09:25:18

 

Example 5 : Add 12 weeks to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL 12 WEEK) as date;

// output : 2022-08-07 09:25:18

 

Example 6 : Add 12 hours to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL 12 HOUR) as date;

// output : 2022-05-15 21:25:18

 

Example 7 : Subtract 2 hours to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL -2 HOUR) as date;

// output : 2022-05-15 07:25:18

 

Example 8 : Add 12 minutes to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL 12 MINUTE) as date;

// output : 2022-05-15 09:37:18

 

Example 9 : Subtract 5 minutes to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL -5 MINUTE) as date;

// output : 2022-05-15 09:20:18

 

Example 10 : Add 12 seconds to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL 12 SECOND) as date;

// output : 2022-05-15 09:25:30

 

Example 11 : Add 7 days & seconds to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL '7 1:03:12' DAY_SECOND) as date;

// output : 2022-05-22 10:28:30

 

Example 12 : Add 7 days & minutes to a date and return the date:

mysql> SELECT DATE_ADD("2022-05-15 09:25:18", INTERVAL '7 1:03' DAY_MINUTE) as date;

// output : 2022-05-22 10:28:18