IsDate function?

drmover

Member
Licensed User
Longtime User
Hello,

Is there any function like IsDate in VB?

If not, how can I validate a text if it's a valid date format?

Thank you,
Elad.
 

JesseW

Active Member
Licensed User
Longtime User
DateTime.DateParse(datestring) will throw an exception if parsing fails, which you could trap with extra coding, but I don't see a method for what your looking for. Perhaps you should suggest it on the Bugs & Wishlist forum? It may be included in one of the third party libraries, but a site search didn't turn up anything.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The best approach is to try to parse and catch the error:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    DateTime.DateFormat = "dd/mm/yy"
    Log(IsValidDate("01/01/2000"))
    Log(IsValidDate("13-12/2007"))
End Sub


Sub IsValidDate(Date As String) As Boolean
    Try
        DateTime.DateParse(Date)
        Return True
    Catch
        Return False
    End Try
End Sub
However, currently the date parser will only throw an error if the string is not formatted correctly. It will not throw an error for "out of range" dates: 35/01/2000

This will be fixed in the next update.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…