1

I am looking into django db backends. I have found that datetime values' timezone are changed to and forth by django, while saving dates into db as well as retrieving them. During this conversion process, django uses database connection's timezone settings.

I have seen that by default for sqlite db, 'UTC' is the timezone. I want to change the database connections options, during the start of django application. How can I do that ?

Thanks in advance.

Mangu Singh Rajpurohit
  • 10,806
  • 4
  • 68
  • 97

1 Answers1

3

From the official Django documentation:

When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, and translates them to the end user’s time zone in templates and forms.

Time zone support is disabled by default.


Because time zone support if disabled by default, you need to manually specify that you want Django to support it. You can do so in your settings.py: For example, if you want UTC +1, then use:

# enable time zone support
USE_TZ = True

# select a timezone
TIME_ZONE = 'Europe/Rome'

Quotes were found from the official Django documentation, which you can access here. I strongly recommend having a read, their documentation is really clear/useful.

Also, if you need other time zones, here is a list of all usable time zones you could use here, which I found from this post.

Community
  • 1
  • 1
Adam Jaamour
  • 1,326
  • 1
  • 15
  • 31