Testing fro valid dates

  • Thread starter Thread starter alex
  • Start date Start date
A

alex

Hi,
is there an easy way in vb to test a string for a valid date (to pass to
a db) like YYYYMMDD or YYYY-MM-DD ?

Thanks
Alex
 
* alex said:
is there an easy way in vb to test a string for a valid date (to pass
to a db) like YYYYMMDD or YYYY-MM-DD ?

Maybe with 'DateTime.ParseExact'. In Whidbey, there will be appropriate
'TryParse*' methods even for 'DateTime'.
 
Hi Alex,

You can convert the string to a date and test it with isdate. But do it
inside a try catch block or it will fail:
Dim st2 As String

st2 = "14/35/03"

Try

If IsDate(CDate(st2)) Then

MessageBox.Show(st2)

End If

Catch

MessageBox.Show("not a valid date")

End Try

HTH,

Bernie Yaeger
 
in addition
as far as i know you don't even have to convert it for that
isdate("1/12/03") will work 2

eric
 
Hi Eric,

My system threw an error if isdate() had a 'non-date' argument.

Bernie
 
Back
Top