469,602 Members | 1,838 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

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 1401
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 guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.