|
|
Title | See if a date string is valid |
Keywords | date string, validate, validation |
Categories | Strings, 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
|
|
|
|
|
|