Determine if a String is a Valid Time

Dates and Math
Phil Fresle

Version Compatibility: Visual Basic 6

More information:
This is one of two examples on the site that checks a value to determine if it is a valid time, the other is at The two versions differ in the following ways:
  • This version relies on the IsDate function. Therefore, it will accept a value such as "13:33 PM" as a valid time. The other version is more stringent and would reject "13:33 PM" as valid (though it would accept "1:33 PM").
  • Because this version relies on the IsDate function, it takes into account international settings, whereas the other version is designed as a stringent check of values on systems in which time values conform to the default American English Regional settings.

    Both versions have their use, depending on the situation, so you should choose the one you need.

Instructions: Copy the declarations and code below and paste directly into your VB project.