The unit for the result is given by the unit argument.
The unit should be one of the following values:
- FRAC_SECOND,
- SECOND,
- MINUTE,
- HOUR,
- DAY,
- WEEK,
- MONTH,
- QUARTER, or
- 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'); |