Search code examples
pythonsqlitetimezonedst

sqlite timezone now


I am using python and sqlite3 to handle a website. I need all timezones to be in localtime, and I need daylight savings to be accounted for. The ideal method to do this would be to use sqlite to set a global datetime('now') to be +10 hours.

If I can work out how to change sqlite's 'now' with a command, then I was going to use a cronjob to adjust it (I would happily go with an easier method if anyone has one, but cronjob isn't too hard)


Solution

  • I'm not 100% on what you're asking, but to keep this simple I would say store your dates in UTC, and present them as local time if need be:

    sqlite> select datetime('now', 'utc');
    2012-07-21 09:58:21
    sqlite> select datetime('now', 'localtime');
    2012-07-21 13:58:33
    

    See SQLite's date and time functions documentation.