Different strftime results from python and sqlite

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 [1]: import sqlite3
In [2]: from datetime import datetime as dt
In [3]: conn = sqlite3.connect(':memory:')  
In [4]: cur = conn.cursor()  
In [5]: cur.execute("select strftime('%s','2012-05-01 12:03:33')").fetchone()
Out[5]: (u'1335873813',)
In [6]: dt.strptime('2012-05-01 12:03:33', '%Y-%m-%d %H:%M:%S').strftime('%s')
Out[6]: '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

1 Respuestas

SQLite's strftime() uses UTC. Python's uses a time zone that is 12 hours (43200 s) earlier.

Respondido el 02 de Septiembre de 12 a las 00:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.