SUBDATE()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Works as a synonym for DATE_INTERVAL expression.
USAGE
SUBDATE(date, INTERVAL number unit)
SUBDATE(date, days)
Argument Name | Description |
|---|---|
| The date that will be subtracted from |
| The number of units to subtract, where |
| The number of days to subtract |
DETAILS
SUBDATE() is a date-time function that subtracts an interval of time from a date.
If a count of days is specified instead of an interval clause, the count is treated as if INTERVAL count DAY had been specified instead of just count.
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.
EXAMPLES
SELECT SUBDATE(CAST('2019-01-15' AS DATE), INTERVAL 11 DAY) AS result1,
SUBDATE(CAST('2019-04-01' AS DATE), INTERVAL 2 YEAR) + 0 AS result2;
+------------+----------+
| result1 | result2 |
+------------+----------+
| 2019-01-04 | 20170401 |
+------------+----------+
SELECT SUBDATE('2020-01-02', INTERVAL 31 DAY);
+----------------------------------------+
| SUBDATE('2020-01-02', INTERVAL 31 DAY) |
+----------------------------------------+
| 2019-12-02 00:00:00 |
+----------------------------------------+
