TIMEDIFF()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns the difference between two TIME
arguments or two DATETIME
arguments.
USAGE
TIMEDIFF(moment1, moment2)
Argument Name | Description |
---|---|
| The two time or datetime values |
DETAILS
TIMEDIFF()
is a date-time function that returns the difference between two TIME
arguments or two DATETIME
arguments.
In string context, the return value is in the hh:mm:ss.uuuuuu
format. The 6-digit microsecond value is always included after the decimal point, even if no microseconds were specified in an input value.
In numeric context, the return value is in the hhmmss.us
format. The value is always floating point, even when microseconds were not specified in the input.
The returned hours can be negative and can exceed 24.
A NULL
is returned if the arguments are not the same data type or either argument is NULL
.
EXAMPLES
SELECT TIMEDIFF('12:05:30', '11:03:27') AS string,
TIMEDIFF('12:05:30', '11:03:27') + 0 AS number;
+-----------------+------------+
| string | number |
+-----------------+------------+
| 01:02:03.000000 | 10203.0000 |
+-----------------+------------+
SELECT TIMEDIFF('1999-01-02 11:00:30',
'1999-01-03 12:01:30') AS string,
TIMEDIFF('1999-01-02 11:00:30',
'1999-01-03 12:01:30') + 0 AS number;
+------------------+--------------+
| string | number |
+------------------+--------------+
| -25:01:00.000000 | -250100.0000 |
+------------------+--------------+
SELECT TIMEDIFF('12:01:30');