Mr. Boy
Mr. Boy

Reputation: 63720

Test if a Time is the next day, not including midnight

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

Answers (1)

Shadowed
Shadowed

Reputation: 966

This should work:

if(secondDate.Date == firstDate.Date.AddDays(1) && secondDate.TimeOfDay != TimeSpan.Zero)

Upvotes: 4

Related Questions