2

datetime is stored in postgres DB with UTC. I could see that the date is 2013-09-28 00:15:52.62504+05:30 in postgres table.

But when I fetch the value via django model, I get the same datetime field as datetime.datetime(2013, 9, 27, 18, 45, 52, 625040, tzinfo=).

USE_TZ is True and TIME_ZONE is 'Asia/Kolkata' in settings.py file. I think saving to DB works fine as DB contains datetime with correct UTC of +5:30.

What am i doing wrong here?

Please help.

Thanks Kumar

7
  • 1
    I can't quite follow the problem. 2013-09-27 18:45 +05:30 is indeed 2013-09-28 00:15. Commented Sep 27, 2013 at 19:21
  • Postgres does not understand Indian Standard Time. you need to do some custom settings. stackoverflow.com/questions/9815412/… Commented Sep 27, 2013 at 19:24
  • What data type is the field in Postgres? Commented Sep 27, 2013 at 20:57
  • @Hyperboreus, yes the value in table is correct, but when I fetch the value via django models it gets converted to UCT+0:00 thus giving value for the model field as datetime.datetime(2013, 9, 27, 18, 45, 52, 625040, tzinfo=). I am not sure why this conversion is done as in django settings I have timezone setup properly. Commented Sep 28, 2013 at 3:48
  • @karthikr, I think posgtres already stores the correct value with timezone, but django model converts it back to America timezone, which I do not understand why. Commented Sep 28, 2013 at 3:55

1 Answer 1

3

The issue has been solved. The problem was that I was using another naive datetime field for calculation of difference in time, whereas the DB field was an aware field. I then converted the naive to timezone aware date, which solved the issue.

Just in case some one needs to know.

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

Comments

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.