Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleSee if a date string is valid
Keywordsdate string, validate, validation
CategoriesStrings, Tips and Tricks, Syntax
 
Use CDate to convert the string into a date. Then use Format to format the string. If it matches the original string, it is a valid date.

Note that this is a little more restrictive than necessary. For example, 12/02/99 does not pass the test if you format the date using the format mask "m/d/yy".

 
Private Function IsValidDate(ByVal txt As String) As Boolean
Dim test_date As String

    ' Assume the check will fail.
    IsValidDate = False

    On Error GoTo DoneChecking
    test_date = CDate(Text1.Text)
    IsValidDate = (Format$(test_date, "m/d/yy") = txt)

DoneChecking:

End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated