Reputation: 63720
This question answers the question how to check if one DateTime
is the next day to a another. But, it will be triggered also in the case that midnight tonight is passed, and I want that special case to count as the same day.
I came up with:
if(secondDate.Date > firstDate.Date && secondDate != secondDate.Date){...}
This checks if the second date has a time component which is a slight shortcut to check for midnight but it feels slightly clunky. Is there a neater/more intuitive way?
Upvotes: 2
Views: 724
Reputation: 966
This should work:
if(secondDate.Date == firstDate.Date.AddDays(1) && secondDate.TimeOfDay != TimeSpan.Zero)
Upvotes: 4