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

kumar
  • 2,570
  • 2
  • 17
  • 18
  • 1
    I can't quite follow the problem. 2013-09-27 18:45 +05:30 is indeed 2013-09-28 00:15. – Hyperboreus Sep 27 '13 at 19:21
  • Postgres does not understand `Indian Standard Time`. you need to do some custom settings. http://stackoverflow.com/questions/9815412/set-custom-timezone-in-django-postgresql-indian-standard-time – karthikr Sep 27 '13 at 19:24
  • What data type is the field in Postgres? – Matt Johnson-Pint Sep 27 '13 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. – kumar Sep 28 '13 at 03: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. – kumar Sep 28 '13 at 03:55
  • @Matt, The field is defined as "date_time timestamp with time zone NOT NULL" – kumar Sep 28 '13 at 03:56
  • 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. Thanks for all you help. – kumar Sep 28 '13 at 10:36

1 Answers1

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.

kumar
  • 2,570
  • 2
  • 17
  • 18