MySQL计算两个日期的时间差函数TIMESTAMPDIFF用法:
TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr2)
返回日期或日期时间表达式datetime_expr1 和datetime_expr2the 之间的整数差。
其结果的单位由interval 参数给出,该参数必须是以下值的其中一个: FRAC_SECOND、SECOND、 MINUTE、 HOUR、 DAY、 WEEK、 MONTH、 QUARTER或 YEAR。
示例如下:
mysql> SELECT TIMESTAMPDIFF(MONTH,’2012-10-01′,’2013-01-13′);
-> 3
mysql> SELECT TIMESTAMPDIFF(YEAR,’2002-05-01′,’2001-01-01′);
-> -1
mysql> SELECT TIMESTAMPDIFF(YEAR,’2012-05-01′,’2013-01-01′);
-> 0
mysql> SELECT TIMESTAMPDIFF(SECOND,’2013-01-01 00:00:00′,’2013-01-31 02:20:00′);
-> 2600400
Post a comment now »
本文目前不可评论
Sorry, the comment form is closed at this time.
No comments yet.