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

Y B
Y B
14,136 Points

datetime conversion works in interpreter but not challenge

Hmm this function seems to work in the interpreter but not the challenge although the challenge does also tell me the output is 15 October 2014 which is the format the question is looking for?

timestrings.py
import datetime


def to_string(dt):
    return dt.strftime('%d  %B %Y')

6 Answers

Mikael Enarsson
Mikael Enarsson
7,056 Points

You have accidentally added 2 whitespaces between '%d' and '%B'. Otherwise everything looks perfect!

Y B
Y B
14,136 Points

Don't worry, I didn't need the quotes round the string....

Y B
Y B
14,136 Points

wow good spot! thank you.

Y B
Y B
14,136 Points

mm I seem to get an error in the second part too?

def from_string(stdate, form):
    return datetime.datetime.strptime(stdate, 'form')
Y B
Y B
14,136 Points

Thanks for the encouragement

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The worst programming errors are the little ones.