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

why is "8/3/2004" > "8/10/2004"?

P: n/a
Hi,

I need to determine the hightest date between e.g. "8/3/2004" and
"8/4/2004".
With this code, i get 'dat2' , which means that "8/4/2004" is higher than
"8/3/2004". That 's right.
But with "8/3/2004" and from "8/10/2004" (also "8/11/2004" ...) i get
'dat1'.
<%
dat1="8/3/2004"
dat2="8/10/2004"
if dat1>dat2 then
response.write("dat1")
else
response.write("dat2")
end if
%>

Why does that not produce 'dat2'?
Thanks
bjorn
Jul 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Bjorn wrote:
Hi,

I need to determine the hightest date between e.g. "8/3/2004" and
"8/4/2004".
With this code, i get 'dat2' , which means that "8/4/2004" is higher
than "8/3/2004". That 's right.
But with "8/3/2004" and from "8/10/2004" (also "8/11/2004" ...) i get
'dat1'.
<%
dat1="8/3/2004"
dat2="8/10/2004"
if dat1>dat2 then
response.write("dat1")
else
response.write("dat2")
end if
%>

Why does that not produce 'dat2'?


Because you are comparing strings. "8/3" is greater than "8/1" when you are
ordering them "alphabetically". You need to convert the strings to dates in
order to compare them as dates. Use the CDate() function, or better yet,
Dateserial(). If you do not have the vbscript documentation, you can
download it from here:
http://tinyurl.com/7rk6

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #2

P: n/a
> dat1=CDate("8/3/2004")
dat2=CDate("8/10/2004")

Jul 19 '05 #3

P: n/a
<%

dat1=FormatDateTime(#8/3/2004 11:59 AM#, 2)

dat2=FormatDateTime(#8/10/2004 11:59 AM#, 2)

if dat1>dat2 then

response.write("dat1")

else

response.write("dat2")

end if

%>

"Bjorn" <no****@rt.sw> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
Hi,

I need to determine the hightest date between e.g. "8/3/2004" and
"8/4/2004".
With this code, i get 'dat2' , which means that "8/4/2004" is higher than
"8/3/2004". That 's right.
But with "8/3/2004" and from "8/10/2004" (also "8/11/2004" ...) i get
'dat1'.
<%
dat1="8/3/2004"
dat2="8/10/2004"
if dat1>dat2 then
response.write("dat1")
else
response.write("dat2")
end if
%>

Why does that not produce 'dat2'?
Thanks
bjorn

Jul 19 '05 #4

P: n/a
thanks

"John" <n o b o d y@spam.com> wrote in message
news:BY***********************@phobos.telenet-ops.be...
dat1=CDate("8/3/2004")
dat2=CDate("8/10/2004")


Jul 19 '05 #5

P: n/a
CJM
The other posters seem to be pointing you in the right direction, but I
thought I'd mention that it is much better if you use a universal date
format since your '8/3/2004' could refer to 8th March or 3rd August
depending on other factors. '20040803' is [unambiguously] March 3rd.

See http://www.aspfaq.com/show.asp?id=2023
Jul 19 '05 #6

P: n/a
And actually, I'm willing to bet that that's exactly what's going.
You're comparing 08 MAR 2004 to 03 AUG 2004.

David H

CJM wrote:
The other posters seem to be pointing you in the right direction, but I
thought I'd mention that it is much better if you use a universal date
format since your '8/3/2004' could refer to 8th March or 3rd August
depending on other factors. '20040803' is [unambiguously] March 3rd.

See http://www.aspfaq.com/show.asp?id=2023


Jul 19 '05 #7

P: n/a
No, it wouldn't take one m/d/y and another m/d/y and only transpose one of
them.

The problem is that the string "8/3..." comes before the string "8/1..."

--
http://www.aspfaq.com/
(Reverse address to reply.)


"David C. Holley" <Da**********@netscape.net> wrote in message
news:OD**************@TK2MSFTNGP10.phx.gbl...
And actually, I'm willing to bet that that's exactly what's going.
You're comparing 08 MAR 2004 to 03 AUG 2004.

David H

CJM wrote:
The other posters seem to be pointing you in the right direction, but I
thought I'd mention that it is much better if you use a universal date
format since your '8/3/2004' could refer to 8th March or 3rd August
depending on other factors. '20040803' is [unambiguously] March 3rd.

See http://www.aspfaq.com/show.asp?id=2023

Jul 19 '05 #8

P: n/a
Aaron [SQL Server MVP] wrote:
No, it wouldn't take one m/d/y and another m/d/y and only transpose
one of them.

The problem is that the string "8/3..." comes before the string
"8/1..."

Hmm - that statement sounds familiar ... ;-)
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #9

P: n/a
David C. Holley wrote:
And actually, I'm willing to bet that that's exactly what's going.
You're comparing 08 MAR 2004 to 03 AUG 2004.


More to the point, CYMD formats can be compared as strings, so no date
conversion is required for sorting. Together with its complete lack of
ambiguity, this format is hard to beat.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.