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 trialJake Williams
2,900 PointsWhy isn't it returning the right year.
Examples I am finding show that this is right but it isn't returning the right year. Is there something else I need to do?
import datetime
## Examples
# to_string(datetime_object) => "24 September 2012"
# from_string("09/24/12 18:30", "%m/%d/%y %H:%M") => datetime
def to_string(date1):
return date1.strftime('%d %B %Y')
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Jake Williams! You're super close. The example it lists is just that... an example. So it's not expecting 2012, it's expecting 2015. The problem here is that you have a few too many spaces in that string. You have two spaces between the day and the month and two spaces between the month and the year instead of just one space between each.
So where you have:
# too many spaces
date1.strftime('%d %B %Y')
You need:
# note the spacing
date1.strftime('%d %B %Y')
Hope this helps!