sql Date conversion not working in sql 2000
-
I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.
-
I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.
Use a parameterized query, that will do the magic around the date format.
-
I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.
It is based on how the systems are setup. Cannot remember the SET command and have to go to work. Sorry.
-
I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.
Your string-representation is a culture-dependent format, a way of displaying a date in a specific culture. Date (and time) itself is not a string, but a number. Make sure it's a
DATE
column in the database, and pass aDate
(not astring
) to the query. Use parameters as suggested.using (var con = new SqlConnection(connectionString))
using (var cmd = con.CreateCommand())
{
cmd.CommandText = "SELECT * FROM SomeTable WHERE MyDate = @MyDate";
cmd.Parameters.AddWithValue("@MyDate", DateTime.Now);
}Bastard Programmer from Hell :suss:
-
I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.
the purpose of a database is to store information, not to format it. Store dates and datetimes in fields with the appropriate type, and let your applications take care of formatting when presenting results to the user. Do not try and have the database format stuff, you will get lots of trouble and never get satisfactory results. And as others have said, use SQL parameters rather than SQL string concatenation, to feed dates and datetimes to the database; thus avoiding all conflicts with regional settings and the like. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.
If the column is a DATETIME, then the statement "it is saving as MM/DD/YYYY format" is untrue. If the output of
SELECT thedate FROM table
shows different formats when executed on different systems, it is because of the "Region and Language" settings of the systems -- see the control panel -- and this is correct behaviour. If you want to override this behaviour (you shouldn't) then format it via the query. And I strongly reccommend ISO 8601 format YYYY-MM-DD. -
It is based on how the systems are setup. Cannot remember the SET command and have to go to work. Sorry.
SET DATEFORMAT DMY
that the one you were thinking of?
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
-
SET DATEFORMAT DMY
that the one you were thinking of?
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
Yep thanks
-
I am trying to insert string date to datetime column with the following way.(Sql2000) CONVERT(DATETIME, @To, 103) but this is not saving the DD/MM/YYYY format in the webserver, but it is working in my local machine.In the webserver sql it is saving as MM/DD/YYYY format.
Put it like, CONVERT( VARCHAR, @To AS DATETIME, 103 ) ) - Happy Coding - Vishal Vashishta