SUB_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 with a count of units subtracted.
USAGE
SUB_DATE_INTERVAL(date, number, unit_string)
Argument Name | Description |
---|---|
| The starting date |
| The number of units to subtract |
| A string specifying a unit a time, such as |
DETAILS
SUB_DATE_INTERVAL()
is a date-time function that subtracts count units of time from a starting date.
An empty string is returned if the unit
value is not valid (e.g., if you specified 'days'
instead of 'day'
).
A NULL
is returned if any argument is NULL
.
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 SUB_DATE_INTERVAL(CAST('2019-01-15' AS DATE), 11, 'day') AS result1,
SUB_DATE_INTERVAL(CAST('2019-04-01' AS DATE), 2, 'year') + 0 AS result2;
+------------+----------+
| result1 | result2 |
+------------+----------+
| 2019-01-04 | 20170401 |
+------------+----------+
SELECT SUB_DATE_INTERVAL('2019-01-15 12:34:56.123456', 56, 'second') AS result;
+----------------------------+
| result |
+----------------------------+
| 2019-01-15 12:34:00.123456 |
+----------------------------+