DATE_ADD()¶
The DATE_ADD() function adds a time/date interval to a date and then returns the date.
Description¶
The DATE_ADD() function adds a time/date interval to a date and then returns the date. If date is NULL, the function returns NULL.
Syntax¶
> DATE_ADD(date,INTERVAL expr unit)
Arguments¶
Arguments |
Description |
|---|---|
date |
Required. The date/datetime to extract the date from. |
expr |
Required. The expr is an expression specifying the interval value to be added or subtracted from the starting date. The expr is evaluated as a string; it may start with a - for negative intervals. |
unit |
Required. The unit is a keyword indicating the units in which the expression should be interpreted. The unit argument can have the following values: |
Examples¶
create table t2(orderid int, productname varchar(20), orderdate datetime);
insert into t2 values ('1','Jarl','2008-11-11 13:23:44.657');
mysql> SELECT OrderId,DATE_ADD(OrderDate,INTERVAL 45 DAY) AS OrderPayDate FROM t2;
+---------+---------------------+
| orderid | orderpaydate |
+---------+---------------------+
| 1 | 2008-12-26 13:23:45 |
+---------+---------------------+
Constraints¶
The date type supports only yyyy-mm-dd and yyyymmdd for now.