w3resource

MySQL DATE_ADD() function

DATE_ADD() function

MySQL DATE_ADD() adds time values (as intervals) to a date value. The ADDDATE() is the synonym of DATE_ADD(). It's a versatile function that helps perform various date and time calculations.

This function is useful in -

  • The primary purpose of the DATE_ADD() function is to perform date arithmetic by adding a specific interval to a given date or datetime value.
  • DATE_ADD() is used to calculate future or past dates based on specified intervals, which is useful for tasks like projecting delivery dates, due dates, or event scheduling.
  • When working with complex date manipulation tasks, such as calculating an employee's retirement date or subscription renewal, DATE_ADD() simplifies the process.
  • For tasks involving seasonal changes or business cycles, DATE_ADD() helps adjust dates to account for shifts in time.
  • In applications that involve event scheduling, DATE_ADD() helps determine future event dates based on specified intervals.
  • DATE_ADD() enhances SQL queries by allowing dynamic calculations in date-related WHERE or HAVING clauses, enabling more precise filtering.

Syntax:

DATE_ADD(date, INTERVAL expr unit)

Arguments:

Name Description
date A date value.
INTERVAL Keyword.
expr A date or datetime expression or a number.
unit An unit, described in the table.

MySQL Version: 8.0

Pictorial Presentation:

Pictorial Presentation of MySQL DATE_ADD() function

Example: MySQL DATE_ADD() function

The following statement will return a date after adding 10 days with the specified date 2008-05-15.

Code:

SELECT DATE_ADD(‘2008-05-15’, INTERVAL 10 DAY) as required_date;

Output:

mysql> SELECT DATE_ADD('2008-05-15', INTERVAL 10 DAY) as required_date;
+---------------+
| required_date |
+---------------+
| 2008-05-25    | 
+---------------+
1 row in set (0.00 sec)

Video Presentation:

All Date and Time Functions:

Click here to see the MySQL Date and time functions.

Previous: CURTIME()
Next: DATE_FORMAT()



Follow us on Facebook and Twitter for latest update.