Date Checking

margret

Well-Known Member
Licensed User
Longtime User
If some one keys in a date and it's not valid, it throws an exception. Is there a function to validate a date? If they key in "04/33/1952" and the day should of been "03" not "33", how can we check this so it will not give an error? I know I can write a date checker but that will be a lot of work and I am hoping for another way?

Thanks,

Margret
 

JesseW

Active Member
Licensed User
Longtime User
Margret, try this

B4X:
Try
    GoodDate = DateTime.DateParse(userdate)
Catch
    GoodDate = ""
End Try

You could even wrap this in a boolean function isDate()
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Thanks Jesse. I knew about that but I was hoping for a function that handles dates. With the code you listed you know if it's an invalid date but you don't know why. Example: Is it an invalid date because of the month, day, year, two // together, etc. I guess I'll have to write one.:(

I really wish B4A had a LostFocus event on the EditText.
Thanks,

Margret
 
Upvote 0
Top