SUBDATE()

Overview

Works as a synonym for DATE_SUB() with one exception: the second argument can be a numeric count of days instead of an INTERVAL expression.

USAGE

SUBDATE(date, INTERVAL number unit)
SUBDATE(date, days)

Argument Name

Description

date

The date that will be subtracted from

INTERVAL count unit

The number of units to subtract, where unit is a date or time unit

days

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.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

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                    |
+----------------------------------------+

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