MySQL 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.
DATE_ADD(date, INTERVAL expr unit)
|date||A date value.|
|expr||A date or datetime expression or a number.|
|unit||An unit, described in the table.|
MySQL Version: 8.0
Example: MySQL DATE_ADD() function
The following statement will return a date after adding 10 days with the specified date 2008-05-15.
SELECT DATE_ADD(‘2008-05-15’, INTERVAL 10 DAY) as required_date;
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)
All Date and Time Functions:
Click here to see the MySQL Date and time functions.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join