https://docs.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql
DATEDIFF ( datepart , startdate , enddate )
返回值是,用结束时间,减去开始时间
CREATE TABLE dbo.Duration ( startDate datetime2 ,endDate datetime2 ); INSERT INTO dbo.Duration(startDate,endDate) VALUES('2007-05-06 12:10:09','2007-05-07 12:10:09'); SELECT DATEDIFF(day,startDate,endDate) AS 'Duration' FROM dbo.Duration; -- Returns: 1