-6

Working on Odoo10, i need to calculate the difference between two fields of datetime type, start and finish, i need the difference to be in minutes. how can i do that ?

Jihane Hemicha
  • 115
  • 1
  • 2
  • 13
  • maybe you can use this : https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-calculate-difference-bitween-two-dates-31486 – DavidS Jun 14 '17 at 14:39
  • @DavidS i need datetime not just date ! and i need it in hours not in days – Jihane Hemicha Jun 14 '17 at 14:48
  • I see, but I hope you can solve this after that help, just you should change the `fmt` and the `days` – DavidS Jun 14 '17 at 14:55
  • But you can see here: https://stackoverflow.com/questions/2788871/date-difference-in-minutes-in-python – DavidS Jun 14 '17 at 14:56

1 Answers1

0

Try with this example:

from dateutil.relativedelta import relativedelta

@api.one 
@api.depends('start_field','finish_field')
def _total_minutes(self):
    if self.start_field and self.finish_field:
        start_dt = fields.Datetime.from_string(self.start_field)
        finish_dt = fields.Datetime.from_string(self.finish_field)
        difference = relativedelta(finish_dt, start_dt)
        days = difference.days
        hours = difference.hours
        minutes = difference.minutes
        seconds = 0
user_odoo
  • 2,284
  • 34
  • 55