DATEDIFF()函数
DATEDIFF(datepart,startdate,enddate)
获取两个日期之间的天数
SELECT DATEDIFF(day,'2008-06-05','2009-08-10') AS days;
SELECT DATEDIFF(day,'2008-08-05 08:00:00','2008-08-10 09:00:00') AS days;
获取两个日期之间的年数
SELECT DATEDIFF(year,'2008-06-05','2009-08-10') AS DiffDate;
SELECT DATEDIFF(year,'2008-08-05 08:00:00','2008-08-10 09:00:00') AS DiffDate;