Odoo Help


How to calculate difference between two dates

Atul Kumar jain
on 3/18/14, 5:05 AM 2,901 views

In My custom module i am unable to calculate difference between two dates

my field is

'date_s':fields.datetime('Start Date'),
'date_e':fields.datetime('End Date'),

I want to calculate difference automatically in my duration field


i correct my function but still i got error like this data_string[found.end():]) ValueError: unconverted data remains: 10:52:57 and my function is def _get_days(self, cr, uid, ids, field_name, args, context=None): res = {} for date in self.browse(cr, uid, ids, context=context): fmt = '%Y-%m-%d' date.date_s = datetime.strptime(date.date_s, fmt) date.date_e = datetime.strptime(date.date_e, fmt) res[date.id] = ((date.date_s-date.date_e).days) or False return res

Atul Kumar jain
on 3/18/14, 7:56 AM
On 3/18/14, 8:05 AM


You may refer the following link: https://accounts.openerp.com/forum/Help-1/question/31486

On 4/8/16, 3:49 AM


d_frm_obj = datetime.datetime.strptime(date_s, DEFAULT_SERVER_DATETIME_FORMAT)

d_to_obj = datetime.datetime.strptime(date_e, DEFAULT_SERVER_DATETIME_FORMAT)

duration = d_to_obj - d_frm_obj

try this

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 3/18/14, 5:05 AM
Seen: 2901 times
Last updated: 4/8/16, 3:49 AM