Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
time/date formatting bug
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... |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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... |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Date and Time formatting | Excel Discussion (Misc queries) | |||
Date and Time Formatting | Excel Worksheet Functions | |||
Formatting Date/Time for NOW() | Excel Discussion (Misc queries) | |||
Date and time formatting | Excel Discussion (Misc queries) | |||
Time & Date Formatting | Excel Worksheet Functions |