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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Anna Carney](https://secure.gravatar.com/avatar/5c4ba145adb084818c720006cf02ccdf?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Anna Carney
1,675 PointsCode works in text editor, but not accepted for challenge question
The challenge question is to:
- Create a function called time_tango
- Function should take 2 arguments, date and time
- It should combine these arguments and return a datetime
I thought I hit all the requirements, and when I run it in my text editor, it returns a datetime without a problem. I've tried returning a datetime object and a datetime string, but neither are accepted. It only responds with "Bummer: Try again!". I'm at a point where I don't know what else to try.
Here's my code: '''python import datetime
def time_tango(date, time): return datetime.datetime.strptime(date + ' ' + time, '%Y-%m-%d %H:%M') '''
import datetime
def time_tango(date, time):
return datetime.datetime.strptime(date + ' ' + time, '%Y-%m-%d %H:%M')
2 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsThis would work if both arguments were strings, but the challenge is asking for a function that will take a date object and a time object as arguments.
So you could use strptime by first making strings out of the objects, or just construct a datetime object using the individual attributes of the arguments, but you might want to consider the easier approach using combine instead.
![Jeff Muday](https://uploads.teamtreehouse.com/production/profile-photos/5900142/micro_jeff_face.jpg)
Jeff Muday
Treehouse Moderator 28,718 PointsYour solution and approach are very sound! However, this challenge wants something really specific -- the entire datetime including all the way down to seconds and microseconds.
For example...
>>> datetime.datetime.now()
datetime.datetime(2022, 4, 4, 17, 21, 27, 448892)
NOTE: this is left for you to solve, the combo
variable is what you should complete!
def time_tango(date, time):
combo = datetime.datetime(date.year, date.month, date.day, time.hour .....
return combo
Hope this helps!
Anna Carney
1,675 PointsAnna Carney
1,675 PointsThis is so much easier than the way I was thinking through the problem! Got it figured out now by using combine(). Thanks for your help!