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

  1. > DATE_ADD(date,INTERVAL expr unit)

Arguments

ArgumentsDescription
dateRequired. The date/datetime to extract the date from.
exprRequired. 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.
unitRequired. 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

  1. create table t2(orderid int, productname varchar(20), orderdate datetime);
  2. insert into t2 values ('1','Jarl','2008-11-11 13:23:44.657');
  3. mysql> SELECT OrderId,DATE_ADD(OrderDate,INTERVAL 45 DAY) AS OrderPayDate FROM t2;
  4. +---------+---------------------+
  5. | orderid | orderpaydate |
  6. +---------+---------------------+
  7. | 1 | 2008-12-26 13:23:45 |
  8. +---------+---------------------+

Constraints

The date type supports only yyyy-mm-dd and yyyymmdd for now.