Reputation: 8310
Given a reference DateTime and given a DateTime to be verified, how can I verify that the second date belongs to the next day (from midnight onwards)?
private bool IsTheNextDay(DateTime toBeVerified, DateTime referenceDate)
{
DateTime date = new DateTime(referenceDate.Year, referenceDate.Month, referenceDate.Day);
DateTime next = date.AddDays(1);
return (toBeVerified >= next);
}
Using the above source code, it works. Are there other better solutions?
Upvotes: 2
Views: 1910
Reputation: 498942
Here is one way:
private bool IsTheNextDay(DateTime toBeVerified, DateTime referenceDate)
{
return referenceDate.Date.AddDays(1) == toBeVerified.Date;
}
The Date
property simply uses 0 for the hourse/minutes/seconds/milliseconds components.
Upvotes: 6