Skip to content

DATE_ADD()

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:
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUA
TER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH

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.