Convert String to DateTime for SQL Server Insert
I have a string that looks like 2017:10:08 13:01:14 and simply need to convert it into an acceptable DateTime format for inserting into a SQL Server field of type datetime.
I would prefer to use something simple and flexible like
Code:
DateTime.Parse(datevar)
...but that is not working. I have also tried
Code:
DateTime.ParseExact(datevar, "yyyy:MM:dd HH:mm:tt", Nothing)
which is not working either. Any help you can provide is appreciated!
Re: Convert String to DateTime for SQL Server Insert
Not sure if this additional code will be helpful...
Code:
Dim img As Image = Image.FromFile(FileName)
Dim dateTaken As String
Dim dateforinsert As DateTime
Dim pitem As PropertyItem
If img.PropertyIdList.Contains(DATE_TAKEN) Then
pitem = img.GetPropertyItem(DATE_TAKEN)
dateTaken = Encoding.UTF8.GetString(pitem.Value, 0, pitem.Value.Length)
dateforinsert = DateTime.ParseExact(dateTaken, "yyyy:MM:dd HH:mm:ss", Nothing)
Else
dateTaken = Nothing
End If