Edmund Rojas
Edmund Rojas

Reputation: 6606

Date validation in visual basic

I am attempting to get a true false boolean to return when I pass a date in a 10/28/2012 format, I have tried IsDate("10/28/2012") however when I do this it always returns false and this should actually return true, does anyone give me an idea as to what I am doing wrong, is there something I should do the the string perhaps before it gets passed into isDate?

Upvotes: 0

Views: 2906

Answers (1)

Chris Stauffer
Chris Stauffer

Reputation: 352

You should use Date.TryParse(s as string, result as Date) As Boolean

Where s is the string you're testing, and result is the Date you would like to store the parsed date in. If you do not care about the Date, and would only like to figure out if the value is a date, then you can just give it new Date. The function will return True if the parse succeeded, or False if it failed.

Upvotes: 2

Related Questions