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 strftime & strptime

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Date and Times strftime task 1 of 1 says correct answer is wrong. Bummer? What's wrong with this code?

In Date and Times strftime challenge task 1 of 1 asks to create a function named to_string that takes a datetime and gives back a string in the format 24 September 2012.

After checking work, I get the message:

Bummer! to_string returned the wrong string. Returned '10 October 2015'.

Isn't '10 October 2015' in the format of '24 September 2012'?

my function is:

def to_string(date1):
    return date1.strftime("%m %B %Y")

So where's the problem?

Edit: fixed typo. Replaced %m with %d:

def to_string(date1):
    return date1.strftime("%d %B %Y")

2 Answers

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

HA! must have been staring at it too long. Thanks!

Jose Luis Lopez
Jose Luis Lopez
19,179 Points

def to_string(datetime): return datetime.strftime("%d %B %Y")

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Thanks. I was able to figure it out from Kenneth's answer.