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

Welser Muñoz
Welser Muñoz
4,447 Points

Code Challengue: Time Tango

I am not passing the challenge, I tested my code on my console and if it works.

combo.py
import datetime

def time_tango(date, time):
    date_time = datetime.datetime.combine(datetime.datetime.strptime("{}".format(date), "%Y-%m-%d"), datetime.datetime.strptime("{}".format(time), "%H:%M:%S").time())
    return date_time

1 Answer

Hi Welser,

You're over thinking the challenge. The combine method accepts a date and a time and combines them into a datetime object. You only need to pass the date and the time in.

Also, you should avoid the use of naming variables the same as built in objects.

import datetime

def time_tango(d, t):
  return datetime.datetime.combine(d, t)