Odoo Help


Calculate number of hours between two days

on 11/19/14, 5:30 AM 747 views

>>> import datetime
>>> datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'2014-11-19 15:53:42'
>>> a='2014-11-19 15:53:42'
>>> b='2015-11-19 15:53:42'

How to calculate number of hours between these two dates (a,b),which method i can follow

Daniele Lanfranchi
On 11/19/14, 6:16 AM

Hello, have you tried using the .total_seconds() function?

delta = (b-a).total_seconds()

This function returns the seconds between two dates. After that, you need to convert it to hours.


Take a look at this.. http://stackoverflow.com/questions/4362491/how-do-i-check-the-difference-in-seconds-between-two-dates

Thanks ...Daniele Lanfranch

on 11/19/14, 6:49 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 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

1 follower(s)


Asked: 11/19/14, 5:30 AM
Seen: 747 times
Last updated: 3/16/15, 8:10 AM