View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
J.E. McGimpsey J.E. McGimpsey is offline
external usenet poster
 
Posts: 493
Default time/date formatting bug

By enclosing the dates in quotes, you're telling the compiler to
compare the dates as strings - "2" in "22:00" comes before "4" in
"4:00", so the second clause is true.

Try

((#10/7/2003 22:00#) = (#10/6/2003 16:00#)) And_
((#10/7/2003 22:00#) <= (#10/7/2003 4:00#))

In article ,
"mike" wrote:

I am running a program with a conditional statement that
looks at two time/dates in "m/d/yyyy h:mm" format. Both
variables for the time/dates are declared as variant. If I
replace the variables with the actual values obtained from
the Immediate Window, an example looks like this:

(("10/7/2003 22:00") = ("10/6/2003 16:00")) And
(("10/7/2003 22:00") <= ("10/7/2003 4:00"))

these conditions above are part of an "if" statement and
when the above is entered in the Immediate Window, "true"
is obtained. This doesn't make sense since
(("10/7/2003 22:00") <= ("10/7/2003 4:00")) is not true.
I even simplified it further and entered the following
times in the Immediate Window:

?"22:15""9:00"
False
?"22:15""10:00"
True

I don't know what is going on.. thanks in advance
mike

if it helps, my original conditional statement is:

If (((sDate & " " & sTime) = Format(DateAdd _
("h", -6, Switching(i -
1).TimeSwitch), "m/d/yyyy h:mm")) And ((sDate & " " &
sTime) <= _
Format(DateAdd("h", 6, Switching(i -
1).TimeSwitch), "m/d/yyyy h:mm"))) Then <code...