Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
9310 Prikazi

Hello,

I am storing a datetime field by converting from string to datetime using datetime package. It's getting saved properly in database with given values. But when I use that field openerp views I get time mismatch.

datetime.strptime(start_date,'%Y-%m-%d %H:%M:%S') 

" 2014-09-18 00:00:00" # saved datetime in database

In browser(views) its showing  09/18/2014 05:30:00

Can anybody tell how to stop this time conversion.

Avatar
Opusti
Best Answer

This is probably due to the Timezone you selected for the related user (Time zone India: GMT + 5.30).

  1. From this LINK (response from Fabien Pinckaers)

    • Data are stored in the database in UTC (not depending on the timezone of your users)

      When the client receives the data, it translates it according to the timezone of the user which is on the global context that comes from the user preferences (so, the date/time you see on the screen is not the same than the one in the database)

      The client sends back the new dates to the server under the UTC format


 

Avatar
Opusti
Avtor

Thanks Bara, I fixed that issue by converting local to UTC timezone. user_time_zone = context.get('tz', False) # can be fetched form logged in user if it is set local = pytz.timezone (user_time_zone) start_date = local.localize(start_date, is_dst=None) # start_date is a naive datetime start_date = start_date.astimezone(pytz.utc)

Related Posts Odgovori Prikazi Aktivnost
3
jun. 25
945
1
jul. 23
3618
4
dec. 22
9577
2
apr. 21
3641
1
okt. 18
4993