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

Melvin Wevers
Melvin Wevers
2,238 Points

I'm not sure what is wrong with the syntax here.

I tried to convert the strings into datetimes and then combine them. However, something is wrong with the syntax. Not sure what..

combo.py
import datetime

date = "2015-01-09"
time = "13:30"

def time_tango(date, time):
  date_return = datetime.datetime.combine(datetime.strftime(date, %Y-%m-%d), datetime.strftime(time, %H:%M))
  return date_return

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The second argument to strftime is a string of how the date/time string is formatted...

Melvin Wevers
Melvin Wevers
2,238 Points

I changed it, but it still is not working

import datetime

date = "2015-01-09"
time = "13:30"

def time_tango(date, time):
  date_return = datetime.datetime.combine(date.strftime('%Y-%m-%d'), time.strftime('%H:%M'))
  return date_return
Melvin Wevers
Melvin Wevers
2,238 Points

I might be blanking out here. But I thought I gave a string of how it needed to be formatted in the initial example

.strftime(date, %Y-%m-%d)
Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Your first example doesn't have %Y-%m-%d as a string. It's just there, causing a syntax error. Your second example doesn't have the date or time strings.

Melvin Wevers
Melvin Wevers
2,238 Points

I think I was making it too difficult, since it didn't need the conversion.

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