Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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...

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date and Time formatting Shannon Excel Discussion (Misc queries) 1 December 23rd 07 08:19 AM
Date and Time Formatting Daren Excel Worksheet Functions 2 June 27th 07 03:10 PM
Formatting Date/Time for NOW() Rob Excel Discussion (Misc queries) 2 April 30th 07 02:34 PM
Date and time formatting Marco Excel Discussion (Misc queries) 7 February 25th 05 10:07 PM
Time & Date Formatting Goodvibes Excel Worksheet Functions 3 December 29th 04 06:13 PM


All times are GMT +1. The time now is 02:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"