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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cursed Dates 1

Status
Not open for further replies.

schase

Technical User
Sep 7, 2001
1,756
0
0
US
Howdy all,

Trying to insert a date/time into mySQL, now according to the documents, you do have to format the time.

However also according to the documents, now() or date()
should both work.

however this SQL
Code:
SQLstmt = "Insert into tblIssue(fldDept,fldDevice,fldStatus,fldIssue,fldDate)"
SQLstmt = SQLstmt & "VALUES(" & replace(request("txtDevice"),"-",",")
SQLstmt = SQLstmt & ",'" & "Open" & "'"
SQLstmt = SQLstmt & ",'" & replace(request("txtDescription"),"'","''") & "'"
SQLstmt = SQLstmt & "," & NOW()
SQLstmt = SQLstmt & ")"

will result with

Code:
[MySQL][ODBC 3.51 Driver][mysqld-4.0.16-nt]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '4:51:57 PM)' at line 1

and using Date() will just insert it as 2001-00-01

any ideas where i'm straying from the proper SQL?

Thank you



"Never underestimate the power of determination"

Stuart
 
Your NOW() call is not embedded in the SQL; it is coded as a function call in whatever language you are using, and returns a value whose format is determined by that language, in this case '4:51:57 PM'. You need to embed the NOW() into the SQL.

-----
ALTER world DROP injustice, ADD peace;
 
Thank you for your reply.

What do you mean by embed?

I am using ASP, the Now() is within my SQL.

"Never underestimate the power of determination"

Stuart
 
You need to change your code to:
[tt]
SQLstmt = "Insert into tblIssue(fldDept,fldDevice,fldStatus,fldIssue,fldDate)"
SQLstmt = SQLstmt & "VALUES(" & replace(request("txtDevice"),"-",",")
SQLstmt = SQLstmt & ",'" & "Open" & "'"
SQLstmt = SQLstmt & ",'" & replace(request("txtDescription"),"'","''") & "'"
SQLstmt = SQLstmt & ",NOW())"
[/tt]

so that the MySQL server receives the string 'NOW()' instead of '4:51:57 PM'.

-----
ALTER world DROP injustice, ADD peace;
 
ahhhhhhhhhhh

I see.

hmmm, interesting. Pretty nifty. Thanks!

"Never underestimate the power of determination"

Stuart
 
sorry - i'm a mySQL bigginer - can we somehowe enter the date using string quote, or for example what if we want to enter a birthdate...?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top