Outdated Version
You are viewing an older version of this section. View current production version.
TIMESTAMPDIFF
Find between two date or datetime objects the time difference in the specified unit.
Syntax
TIMESTAMPDIFF ({YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | MICROSECOND}, date1, date2)
Arguments
- date1, date2: a valid date, datetime, or parsable date string
Return Type
Integer. If date1 or date2 is not a valid date, returns NULL.
Examples
select timestampdiff(QUARTER, '2009-02-13', '2013-09-01');
+----------------------------------------------------+
| timestampdiff(QUARTER, '2009-02-13', '2013-09-01') |
+----------------------------------------------------+
| 18 |
+----------------------------------------------------+
select timestampdiff(SECOND, '2009-02-14 01:17:01', '2009-02-13 23:31:30');
+---------------------------------------------------------------------+
| timestampdiff(SECOND, '2009-02-14 01:17:01', '2009-02-13 23:31:30') |
+---------------------------------------------------------------------+
| -6331 |
+---------------------------------------------------------------------+
Related Topics