1

I am completely stumped trying to save user inputed datetime. It saves, but does some sort of timezone conversion. I have tried setting USE_TZ = True and TIME_ZONE = 'UTC', but for some odd reason, Django saves my Datetime but it subttracts 7 from the hour. For example if I input the datetime as '2014-01-29 16:56:00', when I look at the database, I see '2014-01-29 09:56:00-07'. I have read the timezone docs, but I am completely confused as to why this is happening. Any help would be greatly appreciated!

2
  • is the timezone set correctly in settings.py? Commented Jan 30, 2014 at 1:16
  • I believe so, I have the setting set to TIME_ZONE = 'UTC'. I guess the bigger question is, will Django always try to do some sort of timezone conversion when saving to a model? Commented Jan 30, 2014 at 12:58

2 Answers 2

1

It appears that this is not specifically an issue with Django, but more of an issue with Postgres. Since Django tells Postgres to create a "timestamp with time zone", Postgres stores the timestamp correctly, and sets an offset for when you query that data directly from Postgres, it will display to you the timestamp with the offset applied. But when the data gets back to Django the offset is removed unless you provided an offset. Seems confusing, not sure why it is done this way. For my specific use case I opted to write a custom field to create "timestamp without time zone". Django only creates "timestamp with timezone", so the only way to get around this is to:

  1. alter the table with SQL. Probably not the best choice when deploying to multiple environments if using South.

  2. Create a custom field that creates "timestamp without time zone". This is the route I decided to go. Hopefully it is the correct route.

Thank you to everyone that tried to help me figure this out.

Sign up to request clarification or add additional context in comments.

Comments

0

The Django docs state that the default time zone setting is:

TIME_ZONE = 'America/Chicago'

Here's the link:

https://docs.djangoproject.com/en/dev/ref/settings/#time-zone

They also state a couple of options when setting the TIME_ZONE. One option is to manually set it by name, and here is the link for the TIME_ZONE names list off the Django Doc's:

http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

3 Comments

I have set my time zone setting to 'UTC', but it still subtracts 7 from UTC time when I save. I am currently in the Denver timezone, which is -7 from UTC, but have not set Denver anywhere in my settings. Chicago is -6 from UTC, so it's definitely not grabbing the default somewhere.
check the django docs link above. There may be another time_zone related setting that you need to set so it doesn't default to a -7 time zone from where you are.
I appreciate you trying to help me, but I have read the shit out of those docs, and nothing leads me to why I am getting a -7 time zone when my timezone is set to UTC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.