On Sep 6, 10:47 pm, Aymeric Augustin <aymeric.augus...@polytechnique.org> wrote:
> Under PostgreSQL, I assume I have to use a TIMESTAMP WITH TIME ZONE and set > the connection's timezone to UTC if I want non-Django applications using the > same database to obtain correct results, regardless of their connection's > timezone. To be honest, this is pure speculation; I must check this for each > database engine. Django defaults to "timestamp with time zone" for DateTimeFields on Postgres. Django also explicitly sets the client connection timezone to that specified in settings.py, however normal behaviour for a Postgres client is to inherit the TZ of the host that the client is running on. Naive timestamps (eg. without timezone) in an INSERT are assumed to be of the client connection timezone. SELECTs of "timestamp with time zone" output the UTC offset, for example, immediately after connecting, and without manually specifying the TZ, psql inherits my host's TZ (Europe/Berlin): talk2=> select id, last_login, date_joined from auth_user where id=1; id | last_login | date_joined ----+-------------------------------+------------------------ 1 | 2011-09-05 18:43:38.050294+02 | 2008-05-03 02:29:14+02 I can change to another TZ easily: talk2=> set timezone to 'America/Chicago'; SET talk2=> select id, last_login, date_joined from auth_user where id=1; id | last_login | date_joined ----+-------------------------------+------------------------ 1 | 2011-09-05 11:43:38.050294-05 | 2008-05-02 19:29:14-05 Notice the timestamps are different, and have a -05 UTC offset now instead of a +02. So if you want non-Django applications to use the DB, you just need the application to be aware of the UTC offset included in the output, and apply that accordingly. Or if you prefer, you can indeed just set the client connect TZ to UTC: talk2=> set timezone to UTC; SET talk2=> select id, last_login, date_joined from auth_user where id=1; id | last_login | date_joined ----+-------------------------------+------------------------ 1 | 2011-09-05 16:43:38.050294+00 | 2008-05-03 00:29:14+00 The main point is that whilst the internal storage of timestamps in Postgres is UTC Julian dates, the output is always rendered as localtime for the client connection TZ, whatever that may be. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.