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

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

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

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)
Random Solutions  
 
programming4us programming4us