Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Dates and Times in Python Dates and Times Time Tango

Devin Scheu
Devin Scheu
66,191 Points

Date Time Python

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

Ive been having a very hard time with this.

Hi Devin,

could you tell us what you have done so far?

4 Answers

You almost have it.

The problem is that you try to call a function named combine inside the datetime module. But there is no combine function inside that module but a combine method (methods are called on instances/objects and functions don't).

What you should try to do is call a method named combine, which is inside a class named datetime. And the class datetime is inside a module which is also named datetime.

To not trying to confuse you too much, you only forgot one word in the return line. Do you see it?

Let me know if you need some more help but I think you will get it :D

Jose Luis Lopez
Jose Luis Lopez
19,179 Points

import datetime

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

This is what it worked for me

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Check the docs for the combine() method.

Devin Scheu
Devin Scheu
66,191 Points
import datetime

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

What am I doing wrong, sometimes I confuse syntax's between language.