Actually i hv a problem how to format date in asp.net using VB. i've tried so many solution but all failed. but when i run on local, job done successfully...there's only on server when i publish n run the pages, error will appear on screen...
I got this error "cannot convert string to datetime"
But i am very happy right now coz already hv the solution after tried hundreds times ok...so i want to share here how to format date from string(text) to datetime. because when googles, found so many people out there got same problem.
Solution:-
Dim str_date As Date = DateTime.Parse(txtDate.Text, System.Globalization.CultureInfo.CreateSpecificCulture("en-CA").DateTimeFormat)
str_date = Format(str_date, "MM/dd/yyyy")
sInsert = "INSERT INTO Table_Name (date_created) VALUES ( " & "CONVERT(DATETIME,'" & str_date & "',101)" & ")"
Dim comInsert As New SqlCommand(sInsert, dbconn)
comInsert.ExecuteNonQuery()
comInsert.Dispose()
Hepi besday to me!
1 year ago
No comments:
Post a Comment