I've been trying to store dates as strings in sqlite but I'm having trouble getting the right results when querying. The problem I am having seems to come down to the fact that I'm getting different results using strftime in sqlite and python. I'm converting the same date to seconds in each and getting different results.
In : import sqlite3 In : from datetime import datetime as dt In : conn = sqlite3.connect(':memory:') In : cur = conn.cursor() In : cur.execute("select strftime('%s','2012-05-01 12:03:33')").fetchone() Out: (u'1335873813',) In : dt.strptime('2012-05-01 12:03:33', '%Y-%m-%d %H:%M:%S').strftime('%s') Out: '1335830613'
I was expecting that both would give me the same result. Am I missing something?
Thanks! -Jared Kibele
preguntado el 24 de agosto de 12 a las 01:08
SQLite's strftime() uses UTC. Python's uses a time zone that is 12 hours (43200 s) earlier.