Search code examples
pythonsqlalchemytimezoneutctimestamp-with-timezone

Timestamp with timezone in relation to UTC


I have this timezone America/Sao_Paulo in my database.

Example:

2017-02-07 10:06:32.157564-02

ts = db.Column(db.DateTime(timezone=True), index=True, server_default=func.now())

My question is, this mean that 10:06:32 already have less two hours than UTC? So -2 is just informative and this is the correct time.

Or It means that we need to subtract two hours (-2) from 10:06:32 to get the correct hours to the timezone for America/Sao_Paulo?


Solution

  • I'm in GMT+2 atm, so to mockup your tz, I set it to yours and then select your time ATM and time in UTC same moment:

    t=# set timezone TO 'America/Sao_Paulo';
    SET
    Time: 0.222 ms
    t=# select now() sao_paulo, now() at time zone 'UTC' utc;
               sao_paulo           |            utc
    -------------------------------+----------------------------
     2017-02-07 13:54:35.112992-02 | 2017-02-07 15:54:35.112992
    (1 row)
    
    Time: 0.163 ms