|
Question : Dateformat in SQL SERVER 2005
|
|
HI,
How do i get date in different format as output. User gives a string 11/21/2005 and also gives dateformat MM/DD/YYYY I have to insert this value in SQL SERVER 2005
|
|
Answer : Dateformat in SQL SERVER 2005
|
|
Hi, To answer your original question:
Dim strMyDate As String strMyDate = Format(DateTime.ParseExact("11-21-2005", "MM-dd-yyyy", _ Globalization.CultureInfo.CurrentCulture), "yyyy-MM-dd")
This will convert from MM-dd-yyyy to yyyy-MM-dd
To apply to your code, just replace the example date "11-21-2005" with frmmain.txtdate.Text and SQL to be like:
strsql = "Insert into " & frmmain.txttablename.Text & "( refno," & frmmain.txtdate.Text & ")VALUES(@refno, '" & strMyDate & "')"
I am not sure about your SQL, but make sure date goes like '2005-11-21' - (within apostrophes - as I can remember).
Hope this will help, Good luck.
r1937
|
|
|
|