1

I've seen many different posts across SO about aware timezones in django (i.e. datetimes with a timezone value). Even converting naive datetime to aware I've read online that many applications that deal with timezones usually store everything in UTC to avoid any Day light savings conversions and then use frontend to handle the conversions.

I'd like to know if it's possible to store an aware datetime with the actual timezone in my database. If so, how would I go about it?

So instead of storing something like:

2022-10-13 13:56:00+00:00

I'd like to store:

2022-10-13 13:56:00+04:30 (US/Eastern)

pabhik
  • 21
  • 3
  • 3
    Have you seen docs? https://docs.djangoproject.com/en/dev/topics/i18n/timezones/ – abhivemp Oct 14 '22 at 01:57
  • 1
    Someone correct me if I am wrong but my 2 cent here is that it depends on your database. https://docs.djangoproject.com/en/4.1/topics/i18n/timezones/#timezone. I don't know what your requirements are but the safest and probably best bet would be to go the frontend route and do what's necessary to convert from UTC to whatever timezone you need. That's what all big applications do (think calendar apps) – abhivemp Oct 14 '22 at 02:05
  • You could just store it in another column *PostingTZ* and then store the actual datetime in UTC. P ugly solution imo.. But either way it's gonna be stored raw somewhere.. The Docs suggest having User's timezone stored in their profile. Users have to manually enter it at some point as the server can't tell what it is.. **or** you could do a combination of both and use the user's tz to auto fill the post's tz option – Nealium Oct 14 '22 at 02:18

0 Answers0