TIMESTAMPDIFF()

Overview

Returns an integer count of how far apart the date arguments are in the requested units.

USAGE

TIMESTAMPDIFF(unit, timestamp1, timestamp2)

Argument Name

Description

unit

The unit name keyword (not a string)

timestamp

The two DATE or DATETIME values

DETAILS

TIMESTAMPDIFF() is a date-time function that subtracts the first timestamp from the second timestamp and returns a whole number count of how far apart they are in the requested units.

Any fractional units are rounded down just as if ROUND() had been used.

The two timestamp arguments can be DATE or DATETIME values, and are not required to be the same type.

A NULL is returned if any argument is NULL.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

SELECT TIMESTAMPDIFF(MONTH, '2020-02-01', '2019-02-01');
+--------------------------------------------------+
| TIMESTAMPDIFF(MONTH, '2020-02-01', '2019-02-01') |
+--------------------------------------------------+
|                                              -12 |
+--------------------------------------------------+
SELECT TIMESTAMPDIFF(MONTH, '2019-02-01', '2020-02-15');
+--------------------------------------------------+
| TIMESTAMPDIFF(MONTH, '2019-02-01', '2020-02-15') |
+--------------------------------------------------+
|                                               12 |
+--------------------------------------------------+

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