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 trialKenneth Bagwell Jr
3,698 Pointsnot understanding why I'm not getting a string back
why aren't I getting a string back?
import datetime
def to_string(datetime):
datetime.strftime('%d %B %Y')
return datetime
# from_string("09/24/12 18:30", "%m/%d/%y %H:%M") => datetime
1 Answer
Asher Orr
Python Development Techdegree Graduate 9,409 PointsHi Kenneth! Here's the issue:
import datetime
def to_string(datetime):
datetime.strftime('%d %B %Y')
#the line above needs to be stored in a variable.
return datetime
#you need to return the variable.
#the variable stores the operation that converts your parameter, a datetime object, into a string.
Your code is returning the parameter datetime. When you click "Check Work," the Treehouse checker is passing in a datetime object as the parameter- not a string.
Your code should convert the parameter to a string, then return the string.
I hope this helps. Let me know if you have questions!