error comparing with datetime
Posted by:
adaofu de
Date: July 18, 2015 12:00AM
This is my python code:
timestamp="2015-07-16 13:17:54"
sqli="select distinct from_user from customer where time_stamp>="+timestamp
users=cur.execute(sqli)
And it outputs error:
_mysql_exceptions.ProgrammingError: (1064, "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 '13:17:54' at line 1
While I directly execute "select distinct from_user from customer where time_stamp>=2015-07-16 13:17:54" success
The time_stamp type is datetime. And when I do the following:
timestamp="2015-07-16 13:17:54"
sqli="select distinct from_user from customer where time_stamp>=%s"
users=cur.execute(sqli,timestamp)
It comes to error:
File "response.py", line 76, in do_push
users=cur.execute(sqli,timestamp)
File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py", line 187, in execute
TypeError: not all arguments converted during string formatting
What should be the problem then?
Subject
Written By
Posted
error comparing with datetime
July 18, 2015 12:00AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.