Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default error comparing dates

You are comparing a number (the result of CDate is a number between 0 and
0.99999999) with a text string and relying on VBA to properly interpret the
latter as a time and convert it to a time. IMO, that's risky business. I like
to be in control as much as possible, so I always convert the two variables to
the same type. IOW, if you convert one to a date, you should do the same with
the 2nd.

That said, in the immediate window I executed the following statement: the
result was False, not True

? cdate("10:00 AM") < "10:00:00 AM"
False

Note that

? cDate("10:00 AM") < CDate("10:00:00 AM")

also prints False

On Wed, 20 Oct 2004 20:01:04 -0700, "Fernando"
wrote:


Hi,
Error when comparing a range of dates, returns false instead of true.

code:
dim hrMax as date
Do While CDate(lstMax.List(lstMax.ListCount - 1)) < hrMax
....
loop

explanation:
lstMax (listbox control) has an array of of times ("11:00 AM", "12:00 AM",
"1:00 PM", etc), in the loop, the camparison goes like this:

Do While CDate("10:00 AM") < "10:00:00 AM" -- result: true
Do While CDate("11:00 AM") < "10:00:00 AM" -- result: false
Do While CDate("12:00 AM") < "10:00:00 AM" -- result: false
Do While CDate("1:00 PM") < "10:00:00 AM" -- result: false

why does the 1st returns true?.
when I debug step by step, I can see that the it should return false

This file manages data files, and this error is only present on very few

files

thanks for your help


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
Comparing dates Gareth.Evans Excel Worksheet Functions 0 March 26th 09 08:54 AM
Comparing dates Gareth.Evans Excel Worksheet Functions 3 March 25th 09 07:05 PM
Comparing 3 dates Steve Excel Worksheet Functions 1 May 9th 06 12:10 PM
Comparing dates Debbie F Excel Worksheet Functions 7 September 7th 05 11:57 AM
comparing dates Myriam Excel Programming 3 October 11th 04 04:49 AM


All times are GMT +1. The time now is 09:29 PM.

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

About Us

"It's about Microsoft Excel"