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 Wikipedia Links

Vidhya Sagar
Vidhya Sagar
1,568 Points

CODE CHALLENGE IN DATE and TIME

Create a new function named from_string that takes two arguments: a date as a string and an strftime-compatible format string, and returns a datetime created from them :

2 Answers

datetime.datetime.strptime is necessary when using import datetime.

It looks something like this:

def from_string(date_string, format_string):
     return time.strptime(date_string, format_string)

Shouldn't it be datetime.datetime.strptime(date_string, format_string)? or have you done an aliasing of the import eg:from datetime import datetime; time = datetime