Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Dates and Times in Python (2014) Dates and Times strftime & strptime

Zachary wathen
seal-mask
.a{fill-rule:evenodd;}techdegree
Zachary wathen
Python Development Techdegree Student 7,152 Points

the console is telling me that datetime does not have an attribute called strptime?

not sure what i am missing here...

timestrings.py
## Examples
# to_string(datetime_object) => "24 September 2012"
# from_string("09/24/12 18:30", "%m/%d/%y %H:%M") => datetime
import datetime

def to_string (datetime1):
    new_date = datetime1.strftime("%d %B %Y")
    return new_date

def from_string (date_string, strftime1):
    date_object = datetime.strptime(date_string, strftime1)
    return date_object

1 Answer

The challenge says that module 'datetime' has no attribute 'strptime'. However, the module datetime has a class datetime which has a method strptime.

It should be sufficient to change your first line to from datetime import datetime, but the challenge does not accept that as a solution. Instead, you can change date_object = datetime.strptime(date_string, strftime1) to date_object = datetime.datetime.strptime(date_string, strftime1)