I am using the INSERT statement below to insert NOW into a datetime field in a SQL dbase
<%
varAlert = request.querystring("alertID")
varInspector = session("stUserid")
varDateRead = NOW
dim sqlalerts
Set con = Server.CreateObject("ADODB.Connection")
con.Open MM_inspections_STRING
sqlalerts = "INSERT INTO dbo.tbl_AlertsRead (alertID, inspectorID, dateread) VALUES ('" & varAlert & "' ,'" & varInspector & "','" & varDateRead & "')"
con.Execute sqlalerts
con.Close
Set con = Nothing
%>
but it’s returning :
Microsoft OLE DB Provider for ODBC Drivers error ‘80040e07’
[Microsoft][SQL Server Native Client 10.0][SQL Server]The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
/html/admin/inspectorsAlertView.asp, line 25
line 25 is the execute statement, am at a loss, NOW returns a valid datetime, and the field ‘dateread’ is definitely a datetime field, and the above INSERT has worked dozens of times without a problem.
Today is 13 November – in UK that would be written as 13/11/2012 but in US it would be 11/13/2012. i think you are inserting the date in the wrong format – which will mean that you are trying to use the 13th month.
I suspect that this worked before because your dates would have been valid, but incorrect values stored in your database. Check your database for previously inserted values.