vb.net string to date conversion
Posted on 2014-10-12
This should be really simple, but so often I have problems working with date/time.
I have a string in the format "Sun, 12 Oct 2014 11:33:18 GMT+8"
I need to save this in a SQL database with the datatype "datetime".
In VB.NET I've tried to convert the string to date by using Date.ParseExact, but I keep getting the message "A first chance exception of type 'System.Data.SqlTypes.SqlTypeException' occurred in System.Data.dll"
This is what I tried:
Dim Timestamp As Date
Dim Format As String = "ddd, dd MMM yyyy hh:mm:tt zzz"
Dim provider As CultureInfo = CultureInfo.InvariantCulture
Timestamp = Date.ParseExact(DateString, Format, provider)
I tried with a few variations, with and without the comma after ddd, with 3 or 5 zzz in the end etc.
What am I doing wrong here?