Calculate difference between two dates (number of days)?
The top answer is correct, however if you would like only WHOLE days as an int and are happy to forgo the time component of the date then consider:
(EndDate.Date - StartDate.Date).Days
Again assuming StartDate
and EndDate
are of type DateTime
.
Use TimeSpan object which is the result of date substraction:
DateTime d1;
DateTime d2;
return (d1 - d2).TotalDays;
Assuming StartDate
and EndDate
are of type DateTime
:
(EndDate - StartDate).TotalDays