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 Far Away

Kenneth Bagwell Jr
Kenneth Bagwell Jr
3,698 Points

not sure where I'm going wrong here

I'm slightly confused on how to add timedelta to date.time

far_away.py
import datetime

def far_away(hours=5):
    datetime.datetime.now() + far_away.timedelta(hours=1)
    return datetime

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Hey Kenneth Bagwell Jr, you’ve got the right idea but have a few items incorrect.

You seem to understand timedeltas. The argument passed into the function is already a timedelta object so it can be directly added to the now().

You also need to return the result of the addition instead of the datetime module name. You can return the addition directly, or assign it a name then return that name:

    # both are correct
    return datetime.datetime.now() + hours
    # or
    result = datetime.datetime.now() + hours
    return result

Post back if you need more help. Good luck!!!