TIMEDIFF()

Overview

Returns the difference between two TIME arguments or two DATETIME arguments.

USAGE

TIMEDIFF(moment1, moment2)

Argument Name

Description

moment

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.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

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');

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