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

Einars Vilnis
Einars Vilnis
8,050 Points

what am I doing wrong?

combo.py challenge i feel like i am doing everithing right but ir some how isnt working. where is my problem?? can somebody help me please? thanks

combo.py
import datetime

def time_tango(date, time):
  date = datetime.date(2015, 10, 15)
  date = date.strftime('%d.%m.%Y')
  time = datetime.time(10, 10, 10, 10, 1)
  time = time.strftime('%H:%M')
  datetime1 = '{} {}'.format(date, time)
  new_date = datetime.datetime.strptime(datetime1, '%d.%m.%Y %H:%M')
  return new_date

2 Answers

Hello,

There is a function in datetime that can take a date and a time and give you a datetime object. You can find out more about datetime objects at https://docs.python.org/3/library/datetime.html#datetime-objects

Einars Vilnis
Einars Vilnis
8,050 Points

thank you. i did find combine but it still shows that i return the wrong datetime

Could you provide your updated code so that we can troubleshoot it more? All you should need to do is return the combined datetime object.

Einars Vilnis
Einars Vilnis
8,050 Points

'''def time_tango(date, time):''' ''' date = datetime.date(2015, 10, 15)''' '''time = datetime.time(10, 10, 10, 10, None)''' '''datetime1 = datetime.datetime.combine(date, time)''' '''return datetime1'''

Hello,

In your updated code, it looks like you're doing a lot of unnecessary stuff. You don't need to assign anything to date or time, those values will be passed into the function when it is called. You only need the lines that are creating datetime1 and returning it.

You're welcome. Have fun with Python.

what happens when you try return time_tango? =)

Einars Vilnis
Einars Vilnis
8,050 Points

'''def time_tango(date, time): date = datetime.date(2015, 10, 15) time = datetime.time(10, 10, 10, 10, None) datetime1 = datetime.datetime.combine(date, time) return datetime1'''