Solved

Microsoft OLE DB Provider for SQL Server error '80040e07'

Posted on 2008-10-24
7
1,941 Views
Last Modified: 2012-05-05
Hi there,

I'm getting the following error on a submit page asp -

Microsoft OLE DB Provider for SQL Server error '80040e07'

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

/checkout.asp, line 179

the data that is being sent is in dd/mm/yyyy format, when I try and change the code on the page I get another error, so ideally as a short term I would like to capture this and do the conversion on the database (ms sql) anyway of doing this?

thanks
0
Comment
Question by:garethtnash
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 3

Expert Comment

by:Blackninja2007
ID: 22795319
usually beacuse server is expecting mm/dd/yyyy and not dd/mm/yyyy.

Hope that helps
0
 

Author Comment

by:garethtnash
ID: 22795399
is there a way to change this code -
<input type="text" value="dd/mm/yy" onfocus="this.select();lcs(this)" onclick="event.cancelBubble=true;this.select();lcs(this)">
So that it inputs like -
October 24 2008 ?
Thanks
0
 
LVL 2

Expert Comment

by:fokuszg
ID: 22795481
i am not sure if i understand what are you trying to say but
you could use 3 dropdown menus with days, months, years
let user select the date
myStr= request.form("month") & "/" & request.form("day") & "/" & "/" & request.form("year")

and use cDate(myStr) that you send to mssql.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Expert Comment

by:Blackninja2007
ID: 22795770
I would recommend using either a date picker control or seperate combo's for each date part.
0
 
LVL 16

Accepted Solution

by:
Steve Krile earned 500 total points
ID: 22796893
Well, if you are sure of the format - dd/mm/yyyy with exactly that number of characters - you can do text manipulation in SQL.  Treat the submitted date as a text string, then in sql pull out the parts, and put them back together again as a date....like this.


CREATE FUNCTION dbo.ConvertDate(@dateStr as varchar(20))
RETURNS datetime
AS

   BEGIN
      DECLARE @result as datetime
      DECLARE @DayParam as varchar(2)
      DECLARE @MonthParam as varchar(2)
      DECLARE @YearParam as varchar(4)

     Set @dayParam = substring(@dateStr,1,2)
     set @monthParam = subString(@dateStr,4,2)
     set @yearParam = substring(@dateStr,7,4)


     
      Set @result =  convert(datetime, @monthparam + '/' + @dayParam + '/' + @yearParam


   RETURN @result

   END











Then, in your update procedure, you can do like this:
CREATE Procedure dbo.Update (@dateStr)
UPDATE MyTable
SET Mydate = dbo.Convertdate(@dateStr)
0
 
LVL 16

Expert Comment

by:Steve Krile
ID: 22796921
But...as a warning, the other commenters are correct...handling date formats by the time it gets to SQL can be quite fragile.  Your interface really should handle all the formatting issues, and once you are submitting your data to SQL everything should be *strongly* typed.
0
 

Author Comment

by:garethtnash
ID: 22796992
thank you
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server Generate Scripts Fails 5 34
Loop to go backward 90 days 2 18
VBScript Write Column Headers 3 32
CPU high usage when update statistics 2 28
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now