SQL SERVER: Get total days between two dates

Pod Mays picture Pod Mays · May 20, 2011 · Viewed 371k times · Source

I'm trying to get the total number of days between two days:

1/1/2011
3/1/2011

RETURN
62

Is it possible to do in SQL Server?

Answer

Will A picture Will A · May 20, 2011

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.