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 trialVidhya Sagar
1,568 PointsCODE 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
givens
7,484 Pointsdatetime.datetime.strptime
is necessary when using import datetime
.
Rastko Jovic
14,883 PointsIt looks something like this:
def from_string(date_string, format_string):
return time.strptime(date_string, format_string)
Ullas Savkoor
6,028 PointsShouldn'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