Comparing dates

  • Thread starter Thread starter Philip Townsend
  • Start date Start date
P

Philip Townsend

I am having difficulty with a simple routine as follows:

public static bool VerifyExpirationDate(DateTime date)
{
if(date>=DateTime.Now)return true;
else return false;
}

The problem is that when today's date is passed in, the method returns
false. Any ideas? Thanks!



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
That's probably because of the time portion of the datetime objects you are
comparing. You should send all your datetime objects to have a time of
midnight or something, so that your comparisons effectively only compare the
actual dates.
 
DateTime.Now return a date with a resolution of 10 ms. So if from the
moment you load the 'date' to the moment when the compare occur pass
more then 10 ms it will return true.

If you want to compare only the date part use DateTime.Today which
returns a date with the time part removed.
 
Back
Top