troubleshooting Question

Visual Basic 6 Function - is valid date?

Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America asked on
Visual Basic Classic
2 Comments1 Solution347 ViewsLast Modified:
I need complete working source code for Visual Basic 6 that allows you to pass in a text value and determine if the text value represents a valid date value.

Empty values are always VALID.  In other words, it is okay to leave the date BLANK.  But if you DO enter a must be VALID.

Date values can be 6 characters long or 8 characters long ONLY.

Format will be MMDDYY or MMDDYYYY

//some_boolean_var = DateIsValid date_as_string

These calls would return TRUE

DateIsValid "" (empty string, no spaces)
DateIsValid "022912"
DateIsValid "02292012"

These would return FALSE

DateIsValid "-"
DateIsValid "&"
DateIsValid "&-"
DateIsValid " "  (one space)
DateIsValid "  "  (two (or more) spaces)
DateIsValid " 022912" (space (or some other char) before the otherwise valid date - even though removing the space would make the date valid - the space means this date fails)
DateIsValid "022912 " (space (or some other char) after the otherwise valid date)
DateIsValid "024912" (there is no 49th of February)
DateIsValid "022911" (2011 was not a leap year)
Get vaccinated; Social distance; Wear a mask
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros