How to retrieve rows using datetime (python & mysql) -


this code:

now  = datetime.datetime.now().replace(microsecond=0) curs.execute("select name, msgdate,  test msgdate=%s",(now)) 

i got these msgs:

file "c:\python\lib\site-packages\mysql\connector\cursor.py", line 220, in _process_params   res = list(map(to_mysql,res)) typeerror: 'datetime.datetime' object not iterable during handling of above exception, exception occurred:  traceback (most recent call last):    file "c:\projectse\email\src\a.py", line 65, in <module>     curs.execute("select name, msgdate messages msgdate=%s",(now))   file "c:\python\lib\site-packages\mysql\connector\cursor.py", line 300, in execute     stmt = operation % self._process_params(params)   file "c:\python\lib\site-packages\mysql\connector\cursor.py", line 225, in _process_params   "failed processing format-parameters; %s" % e)   mysql.connector.errors.programmingerror: -1: failed processing format-parameters;    'datetime.datetime' object not iterable 

any tips?

i think should replace:

curs.execute("select name, msgdate, test msgdate=%s",(now)) 

with:

curs.execute("select name, msgdate, test msgdate=%s",%(now)) 

and use time variable:

import time now=time.strftime('%y-%m-%d %h:%m:%s') 

try seeing = str(datetime.datetime.now().replace(microsecond=0)) looks in python interpreter, if you're curious why that's problem.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -