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
alexandracoder0809
2,606 Pointsfrom_string Challenge
Good evening (again)!
I hope it's ok to ask many of these questions but it helps me to understand things more.
I am stuck at this: (Part 2/2) https://teamtreehouse.com/library/dates-and-times-in-python/dates-and-times/strftime-strptime
And my code looks like this:
import datetime
def to_string (datetime):
date=datetime.strftime("%d %B %Y")
return date
def from_string(string1, format1):
date2=datetime.strptime(string1,format1) # it has to be something with strptime but I don't know how to pass those arguments right in
return date2
Thanks in Advance
1 Answer
Juan Pablo Pinto Santana
15,719 PointsHello!
You forgot to import the class datetime itself, you're just importing the datetime module. So, you could just add this at the top of your code:
from datetime import datetime
Or in the function itself:
date2 = datetime.datetime.strptime(string1, format1)
Cheers!
alexandracoder0809
2,606 Pointsalexandracoder0809
2,606 PointsOh no. Thank you. You are right!