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

Ehor Stashchyshyn
Ehor Stashchyshyn
5,201 Points

whats wrong with this code?

help plz cant understand whole day

far_away.py
import datetime
def far_away(timedelta):
    return datetime.datetime.now() - datetime.timedelta(timedelta)
Ehor Stashchyshyn
Ehor Stashchyshyn
5,201 Points

import datetime def far_away(timedelta): return datetime.datetime.now() + datetime.timedelta(timedelta)

its not working same as code above

2 Answers

Andy Hughes
Andy Hughes
8,479 Points

Adding to Steven Parker's comment, you also don't need;

datetime.timedelta(timedelta)

You just need the name of the argument being passed into the function;

+ timedelta

That's good enough to pass the challenge. :)

Steven Parker
Steven Parker
231,275 Points

That's what I meant by "... since the argument is already a timedelta, it doesn't need to be processed by the method (just add it as it is)." :wink:

Andy Hughes
Andy Hughes
8,479 Points

Steven Parker - Haha, oh yes, I've just reread your comment. Apologies my friend :).

I retract my answer......Steven Parker's is correct! :P

Steven Parker
Steven Parker
231,275 Points

The instructions are pretty explicit, they say: "Add that timedelta to datetime.datetime.now() ..."

But this code is subtracting instead of adding. And since the argument is already a timedelta, it doesn't need to be processed by the method (just add it as it is).