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!
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
SUDHARSAN CHAKRAVARTHICourses Plus Student 2,434 Points
Date & Time
Create a new function named from_string that takes two arguments: a date as a string and an strftime-compatible format string, and returns a datetime created from them.
def from_string(date1, date2): x1 = datetime.datetime.strptime(date1, "%m/%d/%y") x2 = datetime.datetime.strptime(date2, "%H:%M") return datetime.datetime.combine(x1, x2)
can anyone confirm me my understanding on challenge ?. there is some mistake.
Ryan Merritt5,789 Points
The two arguments being passed into
from_string() are not two datetime objects as your argument names (
date2) suggest. Instead the arguments are a date represented as a string, and a format for how that string should be parse.
datetime.datetime.strptime() is a great way to turn a string into a datetime object. It takes a date as a string and a format as its two arguments, which is exactly what you have. Good luck!