0

I am adding timestamp in my payload and storing it in the database for every record.

Suppose say a part of my payload is {"content":[{"timestamp":"2017-12-12 08:05:30"}]

This is how I process it.

content['timestamp'] = parser.parse(content['timestamp'],dayfirst=True)

My model has timestamp field as :

timestamp = models.DateTimeField(null=True)

When I check in my database it stores timestamp field as :

2017-12-12 13:35:30

Which should be stored as it is as per my requirement. 2017-12-12 08:05:30

i.e it stores the timestamp field + my local timezone(+5:30) hours.

I want it to store the timestamp field as it is.

I tried other posts where they suggest using del os.environ['TZ'].

Any idea what I may have done which causes this or what could I do to avoid this.

Any help is appreciated.

Akshay Hazari
  • 3,186
  • 4
  • 48
  • 84

2 Answers2

1

So according to this Question the problem is when django converts datetime to postgres timestamptz in the database.

Postgres prevent timestamp with timezone conversion

So I need to have timestamp field in PostgreSQL

In order to do that , I need to use the answer posted in this question.

Can we have django DatetimeField without timezone?

Where I need to specify USE_TZ = False in the settings.

This makes sure while migrating PostgreSQL considers datetimefield to be converted to timestamp and not timestamptz .

Akshay Hazari
  • 3,186
  • 4
  • 48
  • 84
0

You can set a timezone in settings.py

Here is the list of valid timezones:

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

You can use

TIME_ZONE = 'Asia/Calcutta'

for UTC+05:30

Reference from Selcuk Answer

NIKHIL RANE
  • 4,012
  • 2
  • 22
  • 45