SQL SERVER: Get total days between two dates SQL SERVER: Get total days between two dates sql-server sql-server

SQL SERVER: Get total days between two dates


PRINT DATEDIFF(DAY, '1/1/2011', '3/1/2011') will give you what you're after.

This gives the number of times the midnight boundary is crossed between the two dates. You may decide to need to add one to this if you're including both dates in the count - or subtract one if you don't want to include either date.


SQL Server DateDiff

DECLARE @startdate datetime2 = '2007-05-05 12:10:09.3312722';DECLARE @enddate datetime2 = '2009-05-04 12:10:09.3312722'; SELECT DATEDIFF(day, @startdate, @enddate);


You can try this MSDN link

DATEDIFF ( datepart , startdate , enddate )SELECT DATEDIFF(DAY, '1/1/2011', '3/1/2011')