SQLServerCentral.com / Globalization / SQL Server 7,2000 / The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. / Latest PostsInstantForum.NET v2.9.0SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comTue, 03 Mar 2015 16:29:38 GMT20RE: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.http://www.sqlservercentral.com/Forums/Topic740845-230-1.aspxYour database login may have a default language different than English, or the production server's default language may not not match the one to your login. Maybe the agent for the job has another default language as well. Either way default languages may not be matching. It is thus best to always use the universal yyyymmdd string format for dates.Tue, 25 Sep 2012 15:47:51 GMTMMartin1RE: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.http://www.sqlservercentral.com/Forums/Topic740845-230-1.aspxA hint for future projects and implementations...Don't create dynamic SQL statements containing values in your font end. This enables SQL injection and causes problems as your current. Use parameterized statements and you cannot run into those problems.[code="csharp"]///=======================================================// WRONG WAYusing (SqlConnection cn = new SqlConnection("MyConnectionString")){ cn.Open(); string statement = "INSERT INTO MyTable (Id, MyDateColumn) VALUES (1, '06/24/2009')"; using (SqlCommand cmd = new SqlCommand(statement, cn)) { cmd.ExecuteNonQuery(); }}///=======================================================// CORRECT WAYusing (SqlConnection cn = new SqlConnection("MyConnectionString")){ cn.Open(); string statement = "INSERT INTO MyTable (Id, MyDateColumn) VALUES (@Id, @MyDate)"; using (SqlCommand cmd = new SqlCommand(statement, cn)) { SqlParameter paramId = cmd.Parameters.Add("@Id", SqlDbType.Int); SqlParameter paramMyDate = cmd.Parameters.Add("@MyDate", SqlDbType.DateTime); paramId.Value = 1; paramMyDate.Value = DateTime.Now; cmd.ExecuteNonQuery(); }}[/code]FloWed, 24 Jun 2009 04:12:44 GMTFlorian ReischlRE: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.http://www.sqlservercentral.com/Forums/Topic740845-230-1.aspxPlease see the below link[url]http://support.microsoft.com/kb/173907[/url]Wed, 24 Jun 2009 04:04:13 GMTjoeroshanRE: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.http://www.sqlservercentral.com/Forums/Topic740845-230-1.aspxHi,Thanks for u'r quick reply. I think you have understood differently. My problem is "while inserting , i am getting the sql exception". But this is happening only in production server.I can't use the convert function because, i have around 50 pages in my application and have to use this convert function everywhere.Since it is working in my local server, I think this problem is due to some server settings.Please tell me where to change this settings...Wed, 24 Jun 2009 03:43:07 GMTRamalingam SRE: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.http://www.sqlservercentral.com/Forums/Topic740845-230-1.aspxtry convert(datetime,'date',101)Wed, 24 Jun 2009 03:35:10 GMTjoeroshanThe conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.http://www.sqlservercentral.com/Forums/Topic740845-230-1.aspxHi All,We have developed a web appln using ASP.Net 2.0 / Sql Server 2005. In a web form, while inserting a value into a date field , I am getting the following error."The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated."We are sending the value in MM/DD/YYYY format from the application.This works in my development environment but not in the production server.The language assigned to the Sqluser is "English" in both the cases. We don't have access to the production server. What could be the problem? Kindly throw some light on this.Thanks in advanceWed, 24 Jun 2009 03:29:56 GMTRamalingam S