MySQL DATE_ADD() Function
Definition and Usage
The DATE_ADD() function adds a specified time interval to a date.
Syntax
DATE_ADD(date,INTERVAL expr type)
date The parameter is a valid date expression.expr The parameter is the time interval you want to add.
The type parameter can be one of the following values:
Type Value |
---|
MICROSECOND |
SECOND |
MINUTE |
HOUR |
DAY |
WEEK |
MONTH |
QUARTER |
YEAR |
SECOND_MICROSECOND |
MINUTE_MICROSECOND |
MINUTE_SECOND |
HOUR_MICROSECOND |
HOUR_SECOND |
HOUR_MINUTE |
DAY_MICROSECOND |
DAY_SECOND |
DAY_MINUTE |
DAY_HOUR |
YEAR_MONTH |
Example
Assuming we have the following table:
OrderId | ProductName | OrderDate |
---|---|---|
1 | 'Computer' | 2008-12-29 16:25:46.635 |
Now, we want to add 2 days to the 'OrderDate' so that we can find the payment date.
We use the following SELECT statement:
SELECT OrderId,DATE_ADD(OrderDate,INTERVAL 2 DAY) AS OrderPayDate FROM Orders
Result:
OrderId | OrderPayDate |
---|---|
1 | 2008-12-31 16:25:46.635 |