Date comparison quirk?

B

Byron

Hi,

I had a script set up to create a redirect until a certain date, and I
left the script in there after that date thinking it would just be
dormant until I changed the date parameters.

To my surprise, it started redirecting again. I must not be clear on how
dates work.

Here is the very simple code:

<%
if date < "8/20/2005" then
response.redirect(url)
end if
%>

So why does it think that 10/10/2005 < 8/20/2005 ? What am I missing?

Thanks.
 
M

McKirahan

Byron said:
Hi,

I had a script set up to create a redirect until a certain date, and I
left the script in there after that date thinking it would just be
dormant until I changed the date parameters.

To my surprise, it started redirecting again. I must not be clear on how
dates work.

Here is the very simple code:

<%
if date < "8/20/2005" then
response.redirect(url)
end if
%>

So why does it think that 10/10/2005 < 8/20/2005 ? What am I missing?

Thanks.

It's treating them as strings.

Try: if date < DateValue("8/20/2005") then
 
E

Evertjan.

McKirahan wrote on 11 okt 2005 in
It's treating them as strings.
Try: if date < DateValue("8/20/2005") then

and then only if you are sure your server's regional settings
are set on the expected [foreign to me = states side] date
representation, otherwize DateValue("8/9/2005") could mean
either 8 september or 9 august.

Better be sure codewize [meaning not depending on settings
outside your code] and use:

if date < DateValue("2005/8/20") then

or:

if date < DateValue("August 20, 2005") then

or [if a code litteral] use the short version:

if date < #2005/8/20# then
 
B

Bullschmidt

I'd suggest changing this:
if date < "8/20/2005" then

To be this:
if date < DateSerial(2005, 8, 20) then

Best regards,
J. Paul Schmidt, Freelance Web and Database Developer
http://www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
 
L

larrybud2002

Byron said:
Hi,

I had a script set up to create a redirect until a certain date, and I
left the script in there after that date thinking it would just be
dormant until I changed the date parameters.

To my surprise, it started redirecting again. I must not be clear on how
dates work.

Here is the very simple code:

<%
if date < "8/20/2005" then
response.redirect(url)
end if
%>

So why does it think that 10/10/2005 < 8/20/2005 ? What am I missing?

Use DateDiff function

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdatediff.asp
 

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

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top