The ADDDATE() function in MySQL is used to add a specific time/date interval to a given date and return the resulting date.
Definition and Usage
- The
ADDDATE()function allows you to add a specified interval (e.g., days, months, years) to a date or timestamp.
Syntax
ADDDATE(date, INTERVAL value addunit)
OR
ADDDATE(date, days)
Parameter Values
| Parameter | Description |
|---|---|
date |
The date to which the interval will be added. |
value |
The amount of the interval to add (numeric value). |
addunit |
The type of interval to add. It can be one of the following values: |
MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR, and other combinations of time units. |
|
days |
The number of days to add to the given date (alternative syntax). |
Technical Details
- Works in: From MySQL 4.0
- Return Value: A new date or timestamp after adding the specified interval.
Examples
Example 1: Add 10 days to a date
SELECT ADDDATE("2017-06-15", INTERVAL 10 DAY);
Output:
ADDDATE("2017-06-15", INTERVAL 10 DAY)
--------------------------------------
2017-06-25
In this example, 10 days are added to the date 2017-06-15, resulting in 2017-06-25.
Example 2: Add 15 minutes to a datetime
SELECT ADDDATE("2017-06-15 09:34:21", INTERVAL 15 MINUTE);
Output:
ADDDATE("2017-06-15 09:34:21", INTERVAL 15 MINUTE)
---------------------------------------------------
2017-06-15 09:49:21
Here, 15 minutes are added to the datetime 2017-06-15 09:34:21, giving the result 2017-06-15 09:49:21.
Example 3: Add 3 months to a date
SELECT ADDDATE("2023-01-15", INTERVAL 3 MONTH);
Output:
ADDDATE("2023-01-15", INTERVAL 3 MONTH)
--------------------------------------
2023-04-15
In this case, 3 months are added to the date 2023-01-15, resulting in 2023-04-15.
Related Functions
SUBDATE(): Subtracts a specific time/date interval from a date.DATE_ADD(): An alias for theADDDATE()function in MySQL.CURDATE(): Returns the current date.CURRENT_DATE(): Another way to get the current date.
Use Cases
- Date Manipulation: Adding time intervals (like days, months, or years) to a date for future or past events.
- Scheduling: Automatically calculating due dates, expiration dates, or deadlines.