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

hugh ronald
hugh ronald
2,875 Points

Combining two datetimes

The challenge is to create a function that takes two strings(a time and a date), turn them into datetimes and combine them.

When I run my code in a compiler it works correctly. I have tried multiple strptime formats and I cannot get the challenge to complete.

What am I doing wrong?

combo.py
import datetime
import time

def time_tango(date, time):
    today = datetime.datetime.strptime(date, "%x")
    now = datetime.datetime.strptime(time, "%X").time()
    both = datetime.datetime.combine(today, now)
    return both

1 Answer

Steven Parker
Steven Parker
229,644 Points

Since you're using combine, you won't need to use strptime or to create any new variables. The combine function will take the date and time arguments directly.