kumar
kumar

Reputation: 2620

Postgres datetime field fetched without timezone in django

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

Upvotes: 2

Views: 1649

Answers (1)

kumar
kumar

Reputation: 2620

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.

Upvotes: 3

Related Questions