TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2): Returns the integer difference between datetime_expr1 and datetime_expr2 : TIMESTAMPDIFF « Date Time Functions « MySQL Tutorial






The unit for the result is given by the unit argument.

The unit should be one of the following values:

  1. FRAC_SECOND,
  2. SECOND,
  3. MINUTE,
  4. HOUR,
  5. DAY,
  6. WEEK,
  7. MONTH,
  8. QUARTER, or
  9. YEAR.
mysql>
mysql> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');
+------------------------------------------------+
| TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01') |
+------------------------------------------------+
|                                              3 |
+------------------------------------------------+
1 row in set (0.00 sec)








14.47.TIMESTAMPDIFF
14.47.1.TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2): Returns the integer difference between datetime_expr1 and datetime_expr2
14.47.2.SELECT TIMESTAMPDIFF(FRAC_SECOND,'2003-02-01','2003-05-01');
14.47.3.SELECT TIMESTAMPDIFF(SECOND,'2003-02-01','2003-05-01');
14.47.4.SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01');
14.47.5.SELECT TIMESTAMPDIFF(HOUR,'2003-02-01','2003-05-01');
14.47.6.SELECT TIMESTAMPDIFF(DAY,'2003-02-01','2003-05-01');
14.47.7.SELECT TIMESTAMPDIFF(WEEK,'2003-02-01','2003-05-01');
14.47.8.SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01');
14.47.9.SELECT TIMESTAMPDIFF(QUARTER,'2003-02-01','2003-05-01');
14.47.10.SELECT TIMESTAMPDIFF(YEAR,'2003-02-01','2003-05-01');
14.47.11.SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01');