472,110 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

Comparing dates

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!
Nov 18 '05 #1
2 1481
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.

"Philip Townsend" <pt*******@v1tech.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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!

Nov 18 '05 #2
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.
--
____________________
www.bloomfield.as.ro

Philip Townsend wrote:
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!


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike N. | last post: by
2 posts views Thread by Duppypog | last post: by
2 posts views Thread by Manny Chohan | last post: by
6 posts views Thread by Simon Harvey | last post: by
12 posts views Thread by colincolehour | last post: by
4 posts views Thread by cheryl | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.