数据库
首页 > 数据库> > SQL获取两个日期的时间间隔

SQL获取两个日期的时间间隔

作者:互联网

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;

标签:00,05,DATEDIFF,08,日期,SQL,2008,间隔,SELECT
来源: https://www.cnblogs.com/sunline/p/15549262.html