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 trialwicker
2,987 PointsWhat kind of datetimes are you asking me? Now and today?
Here is the task: Write a function named minutes that takes two datetimes and, using timedelta.total_seconds() to get the number of seconds, returns the number of minutes, rounded, between them. The first will always be older and the second newer. You'll need to subtract the first from the second. And I don't get anything with the time. Sadly it is in the end of the course so I can't finish this. I am giving up officially.
import datetime
def minutes(datetime_one, datetime_two):
datetime_one = datetime.datetime.now()
datetime_two = datetime.datetime.now()
return int(timedelta.total_seconds(datetime_one - datetime_two) / 60)
1 Answer
Mark Sebeck
Treehouse Moderator 37,905 PointsHi Wicker. Good try. This was a difficult question. Few things going on here.
First the datetimes are being passed in so no need to set them to now(). They will have datetime values already. So delete these two lines:
datetime_one = datetime.datetime.now()
datetime_two = datetime.datetime.now()
Next instead of using the function int() you want round(). Because int() will do the same as floor() which is just remove the decimals instead of rounding up when it's greater than equal to .5.
Also timedelta.total_seconds should be datetime.timedelta.total_seconds.
Lastly the question states "The first will always be older and the second newer. You'll need to subtract the first from the second. " Little confusing but it should be datetime_two - datetime_one.
If you still can't get it to pass post your new code back to the Community and someone will help you out. Happy coding!
wicker
2,987 Pointswicker
2,987 PointsThank you! I got this.