Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
Django: Store gmt time in database table instead of local time

In my customer model I have two datetime fields for storing created and updated time.

datetime_created = models.DateTimeField(auto_now_add=True)
datetime_updated = models.DateTimeField(auto_now=True)

When I create a customer, Now it is storing the local time in the database, When I get this customer data through API, It is returning the datetime in gmt time. This is fine. But I want to save the gmt time in the database. I think storing local time in database is not a good practice.

Date settings in settings.py file is

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

I have already installed "pip install pytz" module and my database is postgresql.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Best practice is to save it in UTC format.

USE_TZ = True in your settings, Django stores date and time information in UTC in the database otherwise it will store naive date time

about 4 years ago · Santiago Trujillo Report

0

You're rigth, the best practice is to save in UTC your datetime fields, and to convert it to your convenience in your views using pytz or in your templates using tz tag.

IE, you can use pytz to convert your datetime in an specific datetime in your views

import pytz

datetime_with_new_tz = object.created_at.astimezone(pytz.timezone(YOUR_LOCAL_TIMEZONE))`

if you want to convert the timezone in your template, you can use tz

{% load tz %}
{{object.created_at|timezone:YOUR_LOCAL_TIMEZONE}}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!