SUB_TIME_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 TIME
or DATETIME
value that has count time units subtracted.
USAGE
SUB_TIME_INTERVAL(timestamp, count, unit_string)
Argument Name | Description |
---|---|
| The starting |
| The number of units to subtract |
| A string specifying a unit a time, such as |
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_
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 |
+---------------------+