AttributeError: 'datetime' module has no attribute 'strptime'

The Solution to AttributeError: 'datetime' module has no attribute 'strptime' is


If I had to guess, you did this:

import datetime

at the top of your code. This means that you have to do this:

datetime.datetime.strptime(date, "%Y-%m-%d")

to access the strptime method. Or, you could change the import statement to this:

from datetime import datetime

and access it as you are.

The people who made the datetime module also named their class datetime:

#module  class    method
datetime.datetime.strptime(date, "%Y-%m-%d")

~ Answered on 2013-10-20 16:46:37


Most Viewed Questions: