TIMESTAMPDIFF()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
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 |
---|---|
| The unit name keyword (not a string) |
| The two |
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
.
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 |
+--------------------------------------------------+