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 trialAriadna Rodriguez
6,281 PointsI think my reasoning is close but my syntax might be off.
I'm confused if the datetime_object should be passed in as an argument or not.
## 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(datetime_object):
new_dt = datetime.strftime(datetime_object, '%d, %B, %Y')
return new_dt
4 Answers
Steven Parker
231,248 PointsYou're close, but you should call the method directly on the object and not pass the object as an argument. Then, the format should not have commas in it:
new_dt = datetime_object.strftime('%d %B %Y')
Ariadna Rodriguez
6,281 PointsYes! That makes sense. Also the function does work with date_object passed as the argument. Thanks for your help.
Steven Parker
231,248 PointsWhat's the exact syntax that passed the challenge with the object as an argument?
Ariadna Rodriguez
6,281 Pointsimport datetime
def to_string(datetime_object): new_dt = datetime.strftime('%d, %B, %Y') return new_dt
Steven Parker
231,248 PointsMost curious! I get "Bummer: Try again!" when I paste that into the challenge, but that's what I would expect since the argument isn't being used in the code body at all (plus it still has the commas).
Ariadna Rodriguez
6,281 PointsIt was this code it passed.