VB.NET string to datetime
Posted on 2006-10-27
I am wrestling with some code to convert string to datetime in VB.NET, and then insert it into an MSSQL database.
I am using MSSQL, and the format of the datetime field in the MSSQL database is: m/d/yyyy h:mm:ss tt (where tt is AM/PM).
I am combining a string for this from:
a) retrieval from another database table, for the date part
--> MyDate = "SELECT convert(varchar,gamedatetime,101) "
b) Adding in the time from input from textboxes
--> MyTime = Scoretime3.Text & ":" & Scoretime4.Text & ":" & Scoretime5.Text & " PM"
On screen (using a label) I look at the date and it looks fine. But I am having trouble converting it.
I have tried MyDateTime = DateTime.Parse(MyDate & " " & MyTime)
and also tried the Convert and Format function to not avail - always getting an error that string was in the wrong format.
Can someone help me with the correct way to convert my string so it can be inserted in the database ?