0
votes

I have a Django model with a DateTimeField with a postgres 9.3 database as backend.

measure_datetime = models.DateTimeField()

In my Database this created a column like this

ALTER TABLE geoudis_weathermeasurements ADD COLUMN measure_datetime timestamp with time zone;

of type

timestamp with time zone

As you can see it stores datetime with timezone. I inserted the data with a different tool. And when I do a simple query like that

SELECT measure_datetime from geoudis_weathermeasurements where "id" = 44525
"2014-10-01 00:04:54+02"

This looks good. Now I query the data from within Django and this returns for the same row a Datetime object with UTC timezone

2014-09-30 22:04:54+00:00 
tzinfo=UTC
_utcoffset=0:00:00

So it looks like the original timezone information is gone. Of course I could set it to a different timezone but what if I don't know in which timezone the data was measured? Server to display the data can be in a different timezone. Therefor I thought this postgres datatype (timezone with timestamp) is good for.

Am I doing something wrong here? Thanks for any help or suggestions.

EDIT1:

If I set USE_TZ = False in settings.py I get the result I want. It seems to me this behavior is intended by django.

1

1 Answers

1
votes

I don't know Django at all, but I can tell you that if you don't know in which timezone (UTC offset) the data was measured, then you don`t know the time!

Here are your options:

  1. Make sure you work only with UTC (or with one UTC offset). That's best, but you can't always choose what you get.
  2. Work only with local time. That's really troublesome (computer changes location, user changes time zone settings, daylight saving time switches, ...).