DATE_SUB()

Overview

Returns a date with an INTERVAL expression subtracted.

USAGE

DATE_SUB(date, INTERVAL number unit)

Argument Name

Description

date

The starting date

INTERVAL count unit

The interval of time to subtract expressed as a count of units

DETAILS

DATE_SUB() is a date-time function that subtracts an interval 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 SUB_DATE_INTERVAL(). To add instead of subtract, see DATE_ADD().

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

SELECT DATE_SUB(CAST('2019-01-15' AS DATE), INTERVAL 11 DAY) AS result1,
       DATE_SUB(CAST('2019-04-01' AS DATE), INTERVAL 2 YEAR) + 0 AS result2;
+------------+----------+
| result1    | result2  |
+------------+----------+
| 2019-01-04 | 20170401 |
+------------+----------+
SELECT DATE_SUB('2019-01-15 12:34:56.123456', INTERVAL 56 SECOND) AS result;
+----------------------------+
| result                     |
+----------------------------+
| 2019-01-15 12:34:00.123456 |
+----------------------------+

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