# how to find number of days between two dates?

By
Demirel yakito
on 1/19/15, 2:48 AM 1,587 views

#### Solanki Shamji

--Solanki Shamji--

1308
| 5 2 7
Baroda, India
--Solanki Shamji--

Hello!

Solanki Shamji
On 1/19/15, 3:01 AM

You can use following method as reference. This is available in addons/hr_holidays/hr_holidays.py(Line 262 in odoo8)

def _get_number_of_days(self, date_from, date_to):
"""Returns a float equals to the timedelta between two dates given as string."""

DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT)
to_dt = datetime.datetime.strptime(date_to, DATETIME_FORMAT)
timedelta = to_dt - from_dt
diff_day = timedelta.days + float(timedelta.seconds) / 86400
return diff_day

This also works.. :)

Anand
on 1/19/15, 3:08 AM
Anand
On 1/19/15, 2:56 AM

use it....

from datetime import datetime
d1='2014-11-15'
d2='2013-11-30'
d1 = datetime.strptime(d1, "%Y-%m-%d")
d2 = datetime.strptime(d2, "%Y-%m-%d")
print abs((d2 - d1).days)

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.

1 follower(s)

### Stats

 Asked: 1/19/15, 2:48 AM Seen: 1587 times Last updated: 3/16/15, 8:10 AM