Odoo Help


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


Calculate number of hours between two days

on 11/19/14, 5:30 AM 666 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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


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