469,353 Members | 2,246 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Date comparison quirk?

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.
Oct 10 '05 #1
4 2342
"Byron" <sp*******@dorrk.com> wrote in message
news:MP************************@newshost.allthenew sgroups.com...
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
Oct 10 '05 #2
McKirahan wrote on 11 okt 2005 in
"Byron" <sp*******@dorrk.com> wrote in message
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?


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
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 11 '05 #3
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

*** Sent via Developersdex http://www.developersdex.com ***
Oct 17 '05 #4

Byron wrote:
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/de...ctdatediff.asp

Oct 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Donnal Walter | last post: by
2 posts views Thread by Scott Knapp | last post: by
16 posts views Thread by KL | last post: by
6 posts views Thread by MarkAurit | last post: by
3 posts views Thread by Tiya | last post: by
4 posts views Thread by blini | last post: by
4 posts views Thread by anagai | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.