Odoo Help


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.


Adding timezone value in normal datetime

Ashish Singh
on 9/20/14, 6:27 AM 1,255 views

import pytz

from datetime import datetime
from datetime import timedelta

from openerp import SUPERUSER_ID

        user_pool = self.pool.get('res.users')
        user = user_pool.browse(self.cr, SUPERUSER_ID, self.uid)
        tz = pytz.timezone(user.partner_id.tz) or pytz.utc
        # Suppose 'tz' fetch 'Asia/Kolkata'

# Suppose date_end = '2014-06-17 16:25:25'
        date_from = pytz.utc.localize(datetime.strptime(date_end, "%Y-%m-%d %H:%M:%S")).astimezone(tz)

#        Now if i print date_form --->'2014-06-17 16:25:25+05:30' but i want to print it in '2014-06-17 21:55:25'

please help me guys




| 5 4 7
Bikaner, India

OpenERP Devloper at SunARC Technology

On 9/20/14, 8:32 AM

Thanks Prakash

Ashish Singh
on 9/22/14, 1:02 AM

Ben Bernard

--Ben Bernard--
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 9/20/14, 1:04 PM

You really have to check tz value. If this happen

'2014-06-17 16:25:25+05:30' but i want to print it in '2014-06-17 21:55:25'

then tz = pytz.utc.

Thanks Ben Bernard

Ashish Singh
on 9/22/14, 1:02 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

1 follower(s)


Asked: 9/20/14, 6:27 AM
Seen: 1255 times
Last updated: 3/16/15, 8:10 AM