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
Post a Comment