DateTime
-
How could I change the format of the DateTime ? The local Date is in the "dd-mm-yyyy" but SqlDbType is in "mm-dd-yyyy" format . Thanks in advance.
-
How could I change the format of the DateTime ? The local Date is in the "dd-mm-yyyy" but SqlDbType is in "mm-dd-yyyy" format . Thanks in advance.
-
How could I change the format of the DateTime ? The local Date is in the "dd-mm-yyyy" but SqlDbType is in "mm-dd-yyyy" format . Thanks in advance.
If you want to store a date in SQL server, use parametized queeries, and that'll solve the problem, in any format SQL Server uses.
DateTime myDateTime = ..... string sql = "UPDATE People SET BirthDate = @Date WHERE ID_person = 1"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add("@Date", myDateTime); cmd.ExecuteNonQuery();
That will save the correct date, no matter what format is the local computer, and/or SQL Server's computer using. Alternatively, there's a way to change the date format for SQL Server, but I don't remember the exact syntax. Using parametized queries, I don't need it. Also, parametized queries help avoid SQL injection attacks, so I'll recommend them for every circumstance. -- LuisR
Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!
-
How could I change the format of the DateTime ? The local Date is in the "dd-mm-yyyy" but SqlDbType is in "mm-dd-yyyy" format . Thanks in advance.
hi, easy way is give dateTime as string Format.. ex:- DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") Now No need to worry when local time and sqldbtype is different. regards, pubudu.