Reputation: 489
The timestamp when storing in database its correct but while querying it back the value of time is changing.
models.py
aed = models.CharField(max_length=100)
gbp = models.CharField(max_length=100)
timestamp = models.DateTimeField(auto_now= False,auto_now_add=True)
Database Stored Values
2018-01-10 13:17:05.107542+05:30
2018-01-10 13:18:01.803399+05:30
2018-01-10 13:19:01.873091+05:30
2018-01-10 13:20:04.476807+05:30
2018-01-10 13:21:01.913048+05:30
My query Values
2018-01-10 07:47:05.107542+00:00
2018-01-10 07:47:05
2018-01-10 07:49:01.873091+00:00
2018-01-10 07:49:01
2018-01-10 07:51:01.913048+00:00
2018-01-10 07:51:01
2018-01-10 07:48:01.803399+00:00
2018-01-10 07:48:01
2018-01-10 07:50:04.476807+00:00
2018-01-10 07:50:04
The Time is getting changed.
My Settings.py
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
Upvotes: 0
Views: 159
Reputation: 51649
https://www.postgresql.org/docs/current/static/datatype-datetime.html
For
timestamp with time zone
, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's TimeZone parameter, and is converted to UTC using the offset for the timezone zone.When a timestamp with time zone value is output, it is always converted from UTC to the current timezone zone, and displayed as local time in that zone.
formatting mine.
What you see is different client timezone zones - the one you use to query db directly uses +05:30
and the django one - UTC
Upvotes: 3