Solved

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

Posted on 2008-10-24
7
1,932 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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.

920 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

12 Experts available now in Live!

Get 1:1 Help Now