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.


AttributeError: 'module' object has no attribute 'strptime' then how to resolve it?

on 6/5/14, 8:57 AM 2,441 views

Hi to All,

I am new to openerp, i am changing my hr_holidays module leave request as calculating duration field as weekends also that'sway I am changing my code but still I am getting above error


Here my code

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 = [from_dt + timedelta(x + 1) for x in xrange((to_dt - from_dt).days)]
        timedelta +=[from_dt + timedelta(0)]
        sum(1 for day in timedelta if day.weekday() < 5)
        timedelta = to_dt - from_dt 
        diff_day = timedelta.days + float(timedelta.seconds) / 86400
        return diff_day              

-- Here anything wrong means please send me the code for calculating only weekdays from leave request?



| 5 2 8
Ahmadabad, India
On 6/6/14, 6:38 AM


Add the following import in your module:
import datetime

On 6/6/14, 7:56 AM

Hi Nehal,

I was already import the datetime module, but I am getting the same error.

See this link it may be help you http://stackoverflow.com/questions/19480028/attributeerror-module-object-has-no-attribute-strptime-class

on 6/6/14, 8:20 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: 6/5/14, 8:57 AM
Seen: 2441 times
Last updated: 3/16/15, 8:10 AM