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 Time Tango

Eric Hodgins
Eric Hodgins
29,207 Points

Write a function named time_tango that takes a date and a time. It should combine them into a datetime and return it.

Has anyone tried this question? I can't figure it out. Are 'date' and 'time' strings when passed in?

Any help is appreciated!

Thanks, Eric

4 Answers

boog690
boog690
8,987 Points

The two parameters date and time are not strings, they are date and time objects. The package datetime actually has a method called combine which is used when we want to combine a date object with a time object (into a datetime object). Return the two objects combined.

I linked to the combine method. I won't give the answer away but hopefully you can figure it out from the datetime documentation. Best of luck!

import datetime
def time_tango(date, time):
    return datetime.datetime.combine(date, time)

just got past with this code :)

Eric Hodgins
Eric Hodgins
29,207 Points

Thanks! That did the trick.

Thanks forgot the combine(date, time)