?
Solved

conversion of a char data type to a datetime

Posted on 2006-06-14
10
Medium Priority
?
748 Views
Last Modified: 2007-12-19
Grrrr ...

I thought I had this working.

I do this

Dim cn
set cn = createobject("ADODB.Connection")
cn.Open "Provider=SQLOLEDB;Persist Security Info=False;User ID=clientID;Data Source=tcp:x.x.x.x,x;Database=mydb;Integrated Security=SSPI;Language=British"
cn.Execute "INSERT INTO testtable (testdate, testbool) VALUES('" & FormatDateTime(now(), 0) &  "', '2')"
cn.Close
set cn = nothing

I get a crash on
cn.execute etc...


Now I do this

MsgBox CStr(FormatDateTime(now(), 0))

And it says

2006/06/14 11:11:11

But I get the error
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Any ideas?
Thanks


0
Comment
Question by:amoran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16902721
cn.Execute "INSERT INTO testtable (testdate, testbool) VALUES(convert(datetime,'" & Format(now(), "YYYY-MM-DD HH:NN:SS") &  "'120), '2')"
0
 

Author Comment

by:amoran
ID: 16902765
Sorry angel its vbscript
0
 

Author Comment

by:amoran
ID: 16902846
Even if i hardcode it

cn.Execute "INSERT INTO testtable (testdate, testbool) VALUES('1111/11/11 11:11:11','2')"

I get the same error
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 53

Accepted Solution

by:
Ryan Chong earned 120 total points
ID: 16903017
try:

cn.Execute "INSERT INTO testtable (testdate, testbool) VALUES( GetDate(), '2') "

?
0
 

Author Comment

by:amoran
ID: 16903250
ryancys great that worked.

The problem now is my .vbs file with the code below works (it inserts into the table)
but when I put it as a Job in SQL Server it does nothing?

Dim cn
set cn = createobject("ADODB.Connection")
cn.Open "Provider=SQLOLEDB;Persist Security Info=False;User ID=clientID;Data Source=tcp:x.x.x.x,x;Database=mydb;Integrated Security=SSPI;Language=English"
websiteStatus = CStr(WebFileExists("http://dev2.myserver.local"))
cn.Execute "INSERT INTO testtable (testdate, testbool) VALUES(GetDate(),'" & websiteStatus & "')"
cn.Close
set cn = nothing

Function WebFileExists(ByVal vWebAddress)
 Dim oXMLHTTP, vWebText
 Set oXMLHTTP = CreateObject("msxml2.xmlhttp")
 oXMLHTTP.Open "GET", vWebAddress, False
 oXMLHTTP.send
 WebFileExists = 0
 If oXMLHTTP.readyState = 4 And oXMLHTTP.Status = 200 Then WebFileExists = 1
 Set oXMLHTTP = Nothing
 Set vWebText = Nothing
End Function

0
 

Expert Comment

by:satdream
ID: 16909247
can you please check Data Type of "testdate" field. if it's "smalldatetime" change it to "datetime".
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16909499
>The problem now is my .vbs file with the code below works (it inserts into the table)
but when I put it as a Job in SQL Server it does nothing?

this is usually one of the following problems:
* the sql server agent is not started at all (does the job run/completion message)?
* you specified 2 connection methods:
- >User ID=clientID;Data Source=tcp:x.x.x.x,x;Database=mydb;
-> Integrated Security=SSPI;
  in the first part, you specify a login, but no password.
    => try to add the password and remove second part
  in the second part, you specify to use windows login
    => remove the first part, and ensure the sql server agent service runs under a NT account that has been granted the permissions needed to connect



0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 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