Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Issue with Datetime conversion

By
Michael Pol
on 9/18/14, 11:04 AM 1,325 views

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.

1

Med Said BARA

--Med Said BARA--
2664
| 5 5 7
Algeria
--Med Said BARA--
Med Said BARA
On 9/18/14, 6:21 PM

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


 

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)

Michael Pol
on 9/19/14, 3:23 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/18/14, 11:04 AM
Seen: 1325 times
Last updated: 3/16/15, 8:10 AM