Skip to content

DATE_ADD()

Function Description

DATE_ADD() is used to perform date operations: DATE_ADD() function adds a specified time interval to a date. If date is NULL, the function returns NULL.

Function Syntax

> DATE_ADD(date,INTERVAL expr unit)

Parameter definition

Parameters Description
date Required parameters. The date parameter is a legal date expression.
expr Required parameters. The expr parameter is the time interval that needs to be added to date. If expr is a negative number, it can start with "-".
unit Required parameters. The unit parameter can be the following values:
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUA
TER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_SECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_MICROSECOND
DAY_MICROSECOND
DAY_MICROSECOND
DAY_MICROSECOND
YEAR_MONTH

Example

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 |
+----------------------------------------+

limit

Currently, the date format only supports the data formats of yyyy-mm-dd and yyyymmdd.