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

Berkley Frei
Berkley Frei
6,292 Points

I get the correct format requested by the challenge but it won't let me pass.

import datetime

def to_string(datetime): return datetime.strftime('%m %B %Y')

4 Answers

Berkley Frei
Berkley Frei
6,292 Points

Lol, I hate it when this happens, but if you remove the period from "%d %B %Y" it will work. Pretty nit picky if you ask me :)

wow you were right. Would you look at that. That is rather nit picky

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I've updated the code challenge to be both more explicit in what it wants back and more forgiving in how it judges the response. Thanks for bringing it up.

Most of the time, my thought on this is that programming is "nitpicky" and we should learn to be as exact as possible while working. Sometimes, though, it's good to have a bit of wiggle room.

Maxim Andreev
Maxim Andreev
24,529 Points

%m %B %Y is wrong.

https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

%m -> Month as 01-12 %B -> Month as locale’s full name. %Y -> Year as xxxx

you need %d not %m

it's ('%d %B %Y')

Berkley Frei
Berkley Frei
6,292 Points

Oops, duh, you are totally right. I feel a bit silly for posting this but thank you for the reply, sir!

My error is saying: "Bummer! to_string returned the wrong string. Returned '21 October 2015.'."

import datetime

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