python - Passing est datetime to MySql -


in mysql db there column of type datetime. need select records column -- ones less current est date. used code python - datetime of specific timezone determine est date:

import mysqldb import datetime  class est(datetime.tzinfo):     def utcoffset(self, dt):       return datetime.timedelta()      def dst(self, dt):         return datetime.timedelta(0)   def get_est():     return datetime.datetime.now(est())  

here select request:

a = 'select * table1 date <= %s' % get_est() print cursor.execute(a) data = cursor.fetchall() item in data:   print item 

at point, have error of:

file "/usr/lib/python2.7/dist-packages/mysqldb/connections.py", line 36, in defaulterrorhandler     raise errorclass, errorvalue _mysql_exceptions.programmingerror: (1064, "you have error in sql syntax; check manual corresponds mysql server version right syntax use near '= 2013-05-04 13:23:21.776521+00:00' @ line 1") 

how rid of it? notice have use current est datetime , pass sql request.

select * table1 date <= '2013-05-04 13:34:03.461407+00:00' 

it looks date values not in quotes.

a = "select * table1 date <= '%s'" % get_est() 

(i don't know python apologize if syntax incorrect.)


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -