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 trialMelvin Wevers
2,238 PointsI'm not sure what is wrong with the syntax here.
I tried to convert the strings into datetimes and then combine them. However, something is wrong with the syntax. Not sure what..
import datetime
date = "2015-01-09"
time = "13:30"
def time_tango(date, time):
date_return = datetime.datetime.combine(datetime.strftime(date, %Y-%m-%d), datetime.strftime(time, %H:%M))
return date_return
2 Answers
Kenneth Love
Treehouse Guest TeacherThe second argument to strftime
is a string of how the date/time string is formatted...
Melvin Wevers
2,238 PointsI think I was making it too difficult, since it didn't need the conversion.
import datetime
def time_tango(date, time):
return datetime.datetime.combine(date, time)
Melvin Wevers
2,238 PointsMelvin Wevers
2,238 PointsI changed it, but it still is not working
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherThe second argument...
Melvin Wevers
2,238 PointsMelvin Wevers
2,238 PointsI might be blanking out here. But I thought I gave a string of how it needed to be formatted in the initial example
.strftime(date, %Y-%m-%d)
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherYour first example doesn't have
%Y-%m-%d
as a string. It's just there, causing a syntax error. Your second example doesn't have the date or time strings.