Let’s say I have a start DateTime object containing 2012/09/21 23:59:59 and an end DateTime object containing 2012/09/22 00:01:02. The difference between these two objects is little more than a minute, but the number of days belonging to this range of dates is equal to 2.
I have read other similar questions, and I think that TimeSpan and DateTime classes do not provide methods to perform this type of calculation. How to calculate the number of days belonging to a certain range of dates?
Use:
The variable
differencecontains the time between the two dates. For example use the TotalDays property to get the difference in days.If you want to exclude the time portion, use the Date property on DateTime, for example:
TotalDays will be 1 in this case rather than 0.