Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date/Time Insert - Doesn't seem to work!

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-10-01 : 01:04:00
Clayton writes "I've created an insert SQL statement that inserts a date into one field and the time into another. Running it from Query analyzer works, but when i run it from the website, i get the following error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'

[Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

/ir/create_a.asp, line 49


I'm pretty sure I've converted the date properly, here's what I did to convert it.

IDate = FormatDateTime(Request.form("DMonth") & " " & Request.form("DDay") & ", " & Request.Form("DYear"))
ITime = FormatDateTime(Request.form("DTimeHours") & ":" & Request.form("DTimeMinutes") & Request.form("TimeAMPM"))

and my SQL statement is as follows:

insert into Info
(InfoDate, InfoTime)
values ('"&IDate&"', '"&ITime&"')

Both InfoDate and InfoTime are datetime.

So far I've tried putting cDate() around the variables instead of FormatDateTime, but that didn't work either. I've tried Removing all Formatting, which also didn't work. I've tried removing the AM/PM and using different Date formats. I've tried hard coding the Date and Time into the SQL query, but I still got the same error.

insert into Info (InfoDate, InfoTime) values ('30/06/01', '8:04:00 AM')


When I tried to debug it I got this...It looks correct, but It doesn't seem to work.

I'm pretty sure It's SQL Server 2000 we're running on a Windows 2000 Server with all the newest updates for the OS.

Is there a convert function built into SQL?
Is there something I could put in the sql statement
such as:
insert into Info (InfoDate, InfoTime) values (ConvertDate('30/06/01'), ConvertTime('8:04:00 AM'))

Any ideas how to convert it otherwise?"
   

- Advertisement -