Open In App

DATE_ADD() Function in MySQL

Last Updated : 25 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax:

DATE_ADD(date, INTERVAL value addunit)

Parameter: This function accepts two parameters which are illustrated below:

  • date –
    Specified date to be modified.
  • value addunit –
    Here the value is the date or time interval to add. This value can be both positive and negative. And here the addunit is the type of interval to add such as SECOND, MINUTE, HOUR, DAY, YEAR, MONTH, etc.

Returns :

It returns the new date after the addition of a specified time or date.

Example 1:

Getting a new date of “2020-11-22” after the addition of 3 years to the specified date “2017-11-22”.

SELECT DATE_ADD("2017-11-22", INTERVAL 3 YEAR);

Output:

2020-11-22

Example 2:

Getting a new date of “2020-11-22” after the addition of 2 months to the specified date “2020-9-22”.

SELECT DATE_ADD("2020-9-22", INTERVAL 2 MONTH);

Output:

2020-11-22

Example 3:

Getting a new date of “2020-11-22” after the addition of 10 days to the specified date “2020-11-12”.

SELECT DATE_ADD("2020-11-12", INTERVAL 10 DAY);

Output:

2020-11-22

Example 4:

Getting a new date of “2020-11-22 09:12:10” after the addition of 3 hours to the specified date “2020-11-22 06:12:10”.

SELECT DATE_ADD("2020-11-22 06:12:10", INTERVAL 3 HOUR);

Output:

2020-11-22 09:12:10

Example 5:

Getting a new date of “2020-11-22 09:09:10” after the addition of 3 minutes to the specified date “2020-11-22 09:06:10”.

SELECT DATE_ADD("2020-11-22 09:06:10", INTERVAL 3 MINUTE);

Output:

2020-11-22 09:09:10

Example 6:

Getting a new date of “2020-11-22 09:09:10” after the addition of 5 seconds to the specified date “2020-11-22 09:09:5”.

SELECT DATE_ADD("2020-11-22 09:09:5", INTERVAL 5 SECOND);

Output:

2020-11-22 09:09:10


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads