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

Datetime Code Challenge Help!

I tried to use the python doc to help pass this challenge , but either I am not running it correctly or am using the wrong thing. ( https://docs.python.org/2/library/datetime.html#datetime.datetime.combine )

I guess I am not quite understanding what the Challenge is wanting me to do...


import datetime

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

2 Answers

You are very close. This may seem strange, but you need to include datetime twice in your return statement, like so: return datetime.datetime.combine(date, time)

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Yeah, the datetime module has a datetime class inside of it that you need to use. It's weird to type datetime.datetime but you'll a) use this all the time in production code; and b) see this pattern in many other modules, too.

Also, make sure you're always using the docs for Python 3. Your link up there goes to Python 2.