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 trialPatrick Harry
19,114 PointsBummer! `to_string` returned the wrong string. Returned '18 June 2017'.
It says that I am returning the wrong string. It looks correct to me. What am I doing wrong?
## Examples
# to_string(datetime_object) => "24 September 2012"
# from_string("09/24/12 18:30", "%m/%d/%y %H:%M") => datetime
def to_string(datetime_object):
now = datetime_object.now()
return now.strftime("%d %B %Y")
1 Answer
Osher Jacobs
2,226 PointsI suspect this may have something to do with the working environment maybe not accepting the dynamic '.now' as a valid argument. Treehouse would have to confirm this. Try entering a date value as follows and see if it works. My code I just typed up is:
import datetime
def to_string(datetime_object):
date_example = datetime_object.strftime("%d %B %Y")
return date_example
date_var = datetime.datetime(2014,9,24)
print(to_string(date_var))
Hope this helps.
Patrick Harry
19,114 PointsPatrick Harry
19,114 PointsYou're right. I was incorrect including .now(). Thanks!