Wednesday, April 7, 2010

How To Format Date in ASP.Net

Actually i hv a problem how to format date in 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 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.


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)

No comments:

Related Posts with Thumbnails