SUB_TIME_INTERVAL()

Overview

Returns a TIME or DATETIME value that has count time units subtracted.

USAGE

SUB_TIME_INTERVAL(timestamp, count, unit_string)

Argument Name

Description

timestamp

The starting TIME or DATETIME

count

The number of units to subtract

unit_string

A string specifying a unit a time, such as 'hour' or 'minute'

DETAILS

SUB_TIME_INTERVAL() is a date-time function that returns a timestamp with count units added to it.

When given a TIME value:

  • In string context, the return value is in the hh:mm:ss.uuuuuu format.

  • In numeric context, the return value is in the hhmmss.uuuuuu format.

When given a DATETIME value (including passing in a string literal):

  • In string context, the return value is in the YYYY-MM-DD hh:mm:ss format. If fractional seconds were specified, a decimal point and the fractional digits are appended.

  • In numeric context, the return value is currently just the year number.

An empty string is returned if the unit value is not valid (e.g., if you specified 'hours' instead of 'hour').

A NULL is returned if any argument is NULL.

A similar function is DATE_SUB(). To add instead of subtract, see ADD_DATE_INTERVAL().

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

SELECT SUB_TIME_INTERVAL(CAST('14:34:56' AS TIME), 2, 'hour') AS result;
+-----------------+
| result          |
+-----------------+
| 12:34:56.000000 |
+-----------------+
SELECT SUB_TIME_INTERVAL('2020-02-28 14:34:56', 26, 'hour') AS result;
+---------------------+
| result              |
+---------------------+
| 2020-02-27 12:34:56 |
+---------------------+

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