• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

DTPicker/VB6 bug (?)

I've run into the following problem:

Suppose you've got a DTPicker control called dtpDate on your form set to 01/12/2014 (dd/mm/yyyy format). The following code returns False!

Format(dtpDate,"dd/mm/yyyy") >= Format(Date,"dd/mm/yyyy")

I'm running VB6/SP2 on NTWS/SP5 - my clock is set to 24-jun-1999. Isn't this strange behaviour, certainly when the following line does return True as it should:

CDate(Format(dtpDate,"dd/mm/yyyy")) >= Format(Date,"dd/mm/yyyy")

But - and this is the clue:

IsDate(Format(dtpDate,"dd/mm/yyyy")) returns True
TypeName(dtpDate.Value) returns Date

Conclusion: I *HAVE* to use explicite Date types ????

Has anyone seen this before?
1 Solution
I haven't seen this before but here's a bit of advice:

ALWAYS use explicit data types. ALWAYS. VB tries to be nice and does a lot of implicit stuff behind the scenes lulling you into the mistaken belief that it will always work. Until you hit something like this. So don't rely on VB.
I completely agree with caraf_g... I have seen situations where datatypes are VERY VERY important...so always make sure not to trust VB's intrinsic type conversions...
Another point of interest . . if you don't use FORMAT the result returns true. ie  dtpicker1 > date
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Also, if you use the custom formats designed for datepicker the result is true  ie format(dtpicker1,"M/d/yyy") > format(date,"mm/dd/yyyy") . .Case Sensitive ..  which probably the way MS designed it to work with the format function as well.
Comparing dates through the format function is not correct.

You see, Format converts date to a string.
So when you use ...
Format(#01/12/2014#,"dd/mm/yyyy") >= Format(#24/07/1999#,"dd/mm/yyyy")
... it is obvious that, lexically,
"01" < "24"

Try comparing without the format function... it will work fine.



gajendra, did you read BeedleGui's comments (Friday, June 25 1999 - 01:21PM PDT)?

You are making a good point, and you explain it well, but since BeedleGui had already brought up the point 9 hours earlier I think the "politically correct" thing to do would have been to add your remark as a comment, not as an answer.
SLEAuthor Commented:
Thanks all for your interest - this was a 0 points question though.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now