Validating Date From A String

ninel

Active member
Joined
Mar 23, 2005
Messages
32
Location
Land O Lakes, Florida
Programming Experience
3-5
I have a textbox on a form. User will enter date in format YYYYMMDD. How do I validate this string? When I used
cdate(txtDate). I get an error returned.

Thanks,
Ninel
 
That is not a valid date format. So, you would either have to change the format (e.g. YYYY/MM/DD) or manually validate it or split the string apart and insert the "/" slashes and validate the result.
 
VB.NET:
dim strDate as String = TextBox1.Text.SubString(0,4) & "/" & TextBox1.Text.SubString(4,2) & "/" & TextBox1.Text.SubString(6,2)
 
Back
Top