Comparing dates

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!
 
M

Marina

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.
 
B

bloomfield

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top