DATE_ADD()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
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 |
---|---|
| The starting date |
| 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_
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 |
+----------------------------+