Sunday, 10 August 2014

Odoo/ OpenERP: Calculate difference between two dates

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta

date_format = '%Y-%m-%d'

joining_date = '2013-08-23'
current_date = (

d1 = datetime.strptime(joining_date, date_format).date()
d2 = datetime.strptime(current_date, date_format).date()
r = relativedelta(d2,d1)

print r.years
print r.months
print r.days

Thanks!!!!!!!!! Enjoy Programming :)


  1. Interesting! I'm looking for something similar but just for minutes. I've created a datetime field that I populate with trough a server action linked to a button and now I would like to compute the minutes that passed to complete an order using the date_order field as source on pos.order model. Can you tell me how should I edit your syntax? Thanks!

  2. To find the desired results you have to convert both the dates in minutes. Better you check here:

    Check "Ken Cochrane's " answer. It will fix your thing.


Thanks for your valuable comments.