Odoo Help

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


Hope this will helpful.

This also works.. :)

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

use it....

from datetime import datetime
d1 = datetime.strptime(d1, "%Y-%m-%d")
d2 = datetime.strptime(d2, "%Y-%m-%d")
print abs((d2 - d1).days)

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: 1/19/15, 2:48 AM
Seen: 1258 times
Last updated: 3/16/15, 8:10 AM