ADD_DATE_INTERVAL()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns a DATE
or DATETIME
value that has been modified by count date units.
USAGE
ADD_DATE_INTERVAL(date, number, unit_string)
Argument Name | Description |
---|---|
| The starting date |
| The number of units to add |
| The unit for the number in string form, such as |
DETAILS
ADD_DATE_INTERVAL()
is a date-time function that adds an interval of time to a date.
A NULL
is returned if any argument is NULL
or the unit
value is not valid (e.g., if you specified 'days'
instead of 'day'
).
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 similar function is DATE_
EXAMPLES
SELECT ADD_DATE_INTERVAL(CAST('1999-12-01' AS DATE), 31, 'day') AS result1,
ADD_DATE_INTERVAL(CAST('1999-04-01' AS DATE), 2, 'year') + 0 AS result2;
+------------+----------+
| result1 | result2 |
+------------+----------+
| 2000-01-01 | 20010401 |
+------------+----------+
-- Leap year is accounted for
SELECT ADD_DATE_INTERVAL(CAST('2020-02-01' AS DATETIME), 29, 'day') AS result;
+----------------------------+
| result |
+----------------------------+
| 2020-03-01 00:00:00.000000 |
+----------------------------+
SELECT ADD_DATE_INTERVAL('2019-01-15 12:34:00.123456', 56, 'second') AS result;
+----------------------------+
| result |
+----------------------------+
| 2019-01-15 12:34:56.123456 |
+----------------------------+