By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,087 Members | 1,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,087 IT Pros & Developers. It's quick & easy.

Future Date Woes

P: n/a
I have a simple application that handles authentication, and one of the
things it checks is password aging. If I have something like this:

If ("02/14/2007" <= Date.Today.ToString("MM/dd/yyyy")) Then
Messagebox.Show("Date specified is less than current")
Else
Messagebox.Show("Date specified is greater than current")
End If
This is causing problems with authentication, as the future date, when
it rolls into another calander year, this expression consistently
returns that the date specified is less than the current date, even if
the date is 01/01/2007 and the current date is 12/31/2006. I haven't
yet found a way around this short of iterating through each number in
the date starting with the year.. Any suggestions?

Jan 1 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Try converting it to a real date, or reverse the order
of the date format so it's 2007/02/14.

Robin S.
-------------------------------------------
"Kevin" <km******@gmail.comwrote in message
news:11**********************@n51g2000cwc.googlegr oups.com...
>I have a simple application that handles authentication, and one of the
things it checks is password aging. If I have something like this:

If ("02/14/2007" <= Date.Today.ToString("MM/dd/yyyy")) Then
Messagebox.Show("Date specified is less than current")
Else
Messagebox.Show("Date specified is greater than current")
End If
This is causing problems with authentication, as the future date, when
it rolls into another calander year, this expression consistently
returns that the date specified is less than the current date, even if
the date is 01/01/2007 and the current date is 12/31/2006. I haven't
yet found a way around this short of iterating through each number in
the date starting with the year.. Any suggestions?

Jan 1 '07 #2

P: n/a
Your prime issue is that the test you are performing is "02/14/2007" <=
"12/31/2006".

The first character of the string on the left is logically less than the the
first character of the string on the right ("0" < "1") therefore the result
is true.

If you just deal with the values as dates then you will be fine:

Dim _d As New DateTime(2007, 2, 14)

If _d <= Datetime.Today Then
...

I also thingk that you have a logic issue with you test. You are testing for
<= (less than or equal to). This will give a result of true when the 2 dates
are the same and therefore your message is inappropriate. I think your test
should simply be for < (less than).
"Kevin" <km******@gmail.comwrote in message
news:11**********************@n51g2000cwc.googlegr oups.com...
>I have a simple application that handles authentication, and one of the
things it checks is password aging. If I have something like this:

If ("02/14/2007" <= Date.Today.ToString("MM/dd/yyyy")) Then
Messagebox.Show("Date specified is less than current")
Else
Messagebox.Show("Date specified is greater than current")
End If
This is causing problems with authentication, as the future date, when
it rolls into another calander year, this expression consistently
returns that the date specified is less than the current date, even if
the date is 01/01/2007 and the current date is 12/31/2006. I haven't
yet found a way around this short of iterating through each number in
the date starting with the year.. Any suggestions?

Jan 1 '07 #3

P: n/a
Thanks! That worked.
Stephany Young wrote:
Your prime issue is that the test you are performing is "02/14/2007" <=
"12/31/2006".

The first character of the string on the left is logically less than the the
first character of the string on the right ("0" < "1") therefore the result
is true.

If you just deal with the values as dates then you will be fine:

Dim _d As New DateTime(2007, 2, 14)

If _d <= Datetime.Today Then
...

I also thingk that you have a logic issue with you test. You are testing for
<= (less than or equal to). This will give a result of true when the 2 dates
are the same and therefore your message is inappropriate. I think your test
should simply be for < (less than).
"Kevin" <km******@gmail.comwrote in message
news:11**********************@n51g2000cwc.googlegr oups.com...
I have a simple application that handles authentication, and one of the
things it checks is password aging. If I have something like this:

If ("02/14/2007" <= Date.Today.ToString("MM/dd/yyyy")) Then
Messagebox.Show("Date specified is less than current")
Else
Messagebox.Show("Date specified is greater than current")
End If
This is causing problems with authentication, as the future date, when
it rolls into another calander year, this expression consistently
returns that the date specified is less than the current date, even if
the date is 01/01/2007 and the current date is 12/31/2006. I haven't
yet found a way around this short of iterating through each number in
the date starting with the year.. Any suggestions?
Jan 1 '07 #4

P: n/a
Kevin,

The most made error is that if people want to compare dates they still take
the date and time.

To compare Dates you can use on both sides DateTime.Date

I hope this gives an idea,

Cor
Jan 1 '07 #5

P: n/a

"Kevin" <km******@gmail.comwrote in message
news:11**********************@n51g2000cwc.googlegr oups.com...
>I have a simple application that handles authentication, and one of the
things it checks is password aging. If I have something like this:

If ("02/14/2007" <= Date.Today.ToString("MM/dd/yyyy")) Then
Messagebox.Show("Date specified is less than current")
Else
Messagebox.Show("Date specified is greater than current")
End If
This is causing problems with authentication, as the future date, when
it rolls into another calander year, this expression consistently
returns that the date specified is less than the current date, even if
the date is 01/01/2007 and the current date is 12/31/2006. I haven't
yet found a way around this short of iterating through each number in
the date starting with the year.. Any suggestions?
Try enclosing the literal date in Pound-signs ie: if ( #02/14/2007# <= ...
otherwise you're comparing a string to a date.
HTH
Jan 1 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.