SQL 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)