Calculate difference between two dates (number of days)?

leora picture leora · Oct 22, 2009 · Viewed 1.2M times · Source

I see that this question has been answered for Java, JavaScript, and PHP, but not C#. So, how might one calculate the number of days between two dates in C#?

Answer

Greg Beech picture Greg Beech · Oct 22, 2009

Assuming StartDate and EndDate are of type DateTime:

(EndDate - StartDate).TotalDays