DATE_ADD()

Overview

Performs arithmetic operations on the given date value, adding an INTERVAL expression in the specified units.

USAGE

DATE_ADD(date, INTERVAL count unit)

Argument Name

Description

date

The starting date

INTERVAL count unit

The interval of time to add expressed as a count of units

DETAILS

DATE_ADD() is a date-time function that adds an interval of time to a date.

This function is the same as one of the two argument choices for ADDDATE() but does not accept the alternate argument syntax that it also accepts.

It is recommended that you CAST a string argument to a DATE or DATETIME type to ensure you get the return value you expect.

A NULL is returned if any argument is NULL.

A similar function is ADD_DATE_INTERVAL(). To subtract instead of add, see DATE_SUB().

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

SELECT DATE_ADD(CAST('1999-12-01' AS DATE), INTERVAL 31 DAY) AS result1,
       DATE_ADD(CAST('1999-04-01' AS DATE), INTERVAL 2 YEAR) + 0 AS result2;
+------------+----------+
| result1    | result2  |
+------------+----------+
| 2000-01-01 | 20010401 |
+------------+----------+
-- Leap year is accounted for
SELECT DATE_ADD(CAST('2020-02-01' AS DATETIME), INTERVAL 29 DAY) AS result;
+----------------------------+
| result                     |
+----------------------------+
| 2020-03-01 00:00:00.000000 |
+----------------------------+
SELECT DATE_ADD('2019-01-15 12:34:00.123456', INTERVAL 56 SECOND) AS result;
+----------------------------+
| result                     |
+----------------------------+
| 2019-01-15 12:34:56.123456 |
+----------------------------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES