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

Tobias Edwards
Tobias Edwards
14,458 Points

Create a new function named from_string that takes two arguments: a date as a string and a format string, and returns a

Firstly, I'm not sure what the question is asking :S Would I have to use the combine() method?

Any help would be much appreciated.

p.s. I have completed the first challenge (1/2)

timestrings.py
def to_string(dt):
  return dt.strftime("%d %B %Y")

3 Answers

Bart Bruneel
Bart Bruneel
27,212 Points

Hello Tobias,

I've just completed this challenge. You will need the strptime method to solve this one. It takes two arguments: the date as a string and the format string.

Tobias Edwards
Tobias Edwards
14,458 Points

Cool! Thank you! Sometimes the challenges are a bit ambiguous and unclear (for me anyway).

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Thanks, Tobias Edwards. I've updated the prompt a bit and provided two examples in the starter file. Hopefully that'll help prevent confusion for other students.

As for C++, I don't think we have any plans for it at the moment but if there was enough demand, we would certainly look into it.

Regarding error messages, I try to make them as clear as possible but there are always circumstances I may not think of or catch. If you see something obviously confusing/missing/wrong, feel free to email me and I'll get it fixed.

Tobias Edwards
Tobias Edwards
14,458 Points

Thanks for the reply, keep up the awesome tutorials!

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Hmm, not sure how to make this prompt less ambiguous. Any suggestions, Tobias Edwards?

Tobias Edwards
Tobias Edwards
14,458 Points

"Create a new function named from_string that takes two arguments - a date as a string and a date as a formatted string - and returns a datetime created from them"

This may seem a bit repetitive, but maybe the arguments that should be passed in could be a bit clearer? At the moment it says "a date as a string and a format string", which makes me think the arguments should be a date as a string (this is fine), but then "format string" (I feel) is not as clear. This is because "format string" doesn't refer to date (for me anyway), so this makes me think, just a regular formatted string.

I was a bit confused :S

Maybe add some comments to the program as you have done in previous challenges?

However, everyone else seems to be getting on fine so it might just be me lol

Lastly, I'm kinda' cheating when I say this, but will there be a C++ lesson guide? (I think that would be amazing!) Also, if I was to type something wrong in the challenges, for example, I missed something minor but the syntax was fine, could the "error" message be a bit more clearer? I don't want to compare, but when I have used 'Codecademy's Python tutorial series in the past, their error messaging is a lot clearer.

Anyway, good job, Kenneth! Love the Python series!