1. 程式人生 > >MySQL函式TIMESTAMPDIFF( )基本用法

MySQL函式TIMESTAMPDIFF( )基本用法

語法如下:
timestampdiff(unit,datetime_expr1,datetime_expr2) --

示例:

select timestampdiff(year,'2002-05-01','2001-01-01'); -- -1
select timestampdiff(day ,'2002-05-01','2001-01-01'); -- -485
select timestampdiff(hour,'2008-08-08 12:00:00','2008-08-08 00:00:00'); -- -12

總結:

MySQL timestampdiff() 函式比 datediff() 功能強多了,datediff() 只能計算兩個日期(date)之間相差的天數。