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 = (datetime.today()).strftime(date_format)

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 :)

4 comments:

  1. Interesting! I'm looking for something similar but just for minutes. I've created a datetime field that I populate with datetime.datetime.now() 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!

    ReplyDelete
  2. To find the desired results you have to convert both the dates in minutes. Better you check here: http://stackoverflow.com/questions/2788871/python-date-difference-in-minutes

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

    ReplyDelete
    Replies
    1. Yes! Exactly what I need! Thanks!

      Delete

Thanks for your valuable comments.

Odoo 10: Close wizard and open standard form

Hi, Today we are going to learn how to open standard form after saving data in wizard. Let's say I have created an wizard to fill bas...