MySQL timestampdiff()函數
TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2)
返回日期或日期時間表達式datetime_expr1 和 datetime_expr2 之間的整數差,結果的單位是由該單元參數給出。單位的合法值的說明與在TIMESTAMPADD()函數列出相同。
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)