Solved

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

Posted on 2008-10-24
7
1,928 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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

744 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

16 Experts available now in Live!

Get 1:1 Help Now