CDATE - System.InvalidCastException - Cast from string to type Date is not valid
Apr 19th, 2007 by Onyrix 770 Views |
Email This Post
|
Print This Post
Suppose you have the code:
And you get the error:
Dim date_datetime as DateTime
date_datetime = CDate(Textbox1.Text)
Exception Details: System.InvalidCastException: Cast from stringMaybe you have some collision between Regional settings and your .Net settings…
“dd/MM/yyyy” to type ‘Date’ is not valid
No problem - do not use CDate but use this piece of code:
Dim date_datetime as DateTime
date_datetime = DateTime.ParseExact(Textbox1.Text, “dd/MM/yyyy”, System.Globalization.CultureInfo.CurrentCulture)

del.icio.us
Digg
Furl
Reddit
Technorati