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.

2 Answers 2

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 .

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Yes, we can , I had set it to UTC. Here I don't wish to use timezone but store it as it is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.