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 Deltas

Y B
Y B
14,136 Points

Can't get this question in time delta quiz

This works in the interpreter but not in the time delta quiz when asked to create a time delta for 5 minutes I used:

datetime.timedelta(minutes=5)

(ie filling in minutes and 5 for the quiz)

but unfortunately that fails?

6 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The question is to go back 5 minutes. So you want -5 not 5.

Abhishek Gangadhar
Abhishek Gangadhar
9,467 Points

Isn't a timedelta only associated with (days, seconds, microseconds) I thought you couldnt use minutes in the case of timedeltas

Y B
Y B
14,136 Points

Ah... I had to laugh when I read your answer - silly me I didn't see the go back bit.

Thanks.

2 issues with this quiz question. 1) "Create a timedelta that goes back 5 minutes." does not specify whether the timedelta will be added or subtracted.
2) datetime.timedelta(seconds = -5*60) fails the quiz but works in python.

I'm running Python 3.4 along with the workspace.

Interesting, When I dir(datetime.datetime), 'minute' shows up as a parameter but fails in test. So I tried 'seconds=-300' which works in Python but fails on the quiz (see YB's post)

But, I changed it to 'minutes=-5' and that worked for both Python and the quiz.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

datetime.datetime and datetime.timedelta are not the same thing.

Stephen Hutchinson
Stephen Hutchinson
8,426 Points

Found a problem in the tests:

datetime.timedelta(seconds=-300)

The above fails

datetime.timedelta(minutes=-5) should work fine.