Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering the date into a sql script

Status
Not open for further replies.

llaurit

Programmer
Aug 17, 2000
9
US
I am trying to take a date/time field from a database. This is the code that I have been using. I know everything works except for the date format. Please let me know what the correct format is. Thanks!

strAddNew = "INSERT INTO tblLog (Date, StartTime, EndTime, CustomerID, Employee, Category, Rate, BillableHours, Billed, Notes) "
strAddNew = strAddNew & "VALUES (#" & strDate & "#, '" & strStart & "', '" & strEnd & "', '" & strClient & "', '" & strEmployee & "', '" & strCategory & "', " & strBillRate & ", " & strBillHour & ", '" & strBilled & "', '" & strNote & "');"
 
try this:

strAddNew = "INSERT INTO tblLog (Date, StartTime, EndTime, CustomerID, Employee, Category, Rate, BillableHours, Billed, Notes) "
strAddNew = strAddNew & "VALUES (" & CDate(strDate) & ", '" & strStart & "', '" &
strEnd & "', '" & strClient & "', '" & strEmployee & "', '" & strCategory & "', " &
strBillRate & ", " & strBillHour & ", '" & strBilled & "', '" & strNote & "');"
 
I tried using the CDate and I still got an error. Thank you anyway!!
Lynn
 
different databases (db2, SQL, access, etc...) require different date/time formats, you need to find out what format your database uses, and convert accordingly
 
Try to convert date to string and not to date:
CStr(strDate)if you use SQL Server

 
Ray, my problem was that I couldn't have "Date" as the field name in my db. Once I changed that the CDate and # format worked. Thanks!
Lynn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top