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 trialTyler Cortez
2,771 Pointswrite a function named minutes..timedelta
little confused here none of the videos I've seen have touched on how to do this. ty
import datetime
def minutes (day1, day2):
timedelta = day2 - day1
return abs(timedelta.total_seconds())
2 Answers
jb30
44,807 PointsYour function currently returns the number of seconds. Try converting the seconds to minutes, then rounding the number of minutes by using the round
function. For example, round(0.9)
gives the result 1
.
Using the abs
function is unnecessary in this case, since the challenge specifies that the first parameter refers to the older datetime.
Andy Hughes
8,479 PointsHey there, I also got stuck on this.
Looking at yours, you are good up to the return. Here's the steps I used in the exercise:
- Import datetime - which you've done
- Create the function with two dates - which you've done
- Create a timedelta using the two dates - which you've done
- Get total seconds and store it for use - Think about how you stored your timedelta. Can you do the same for total seconds?
- Convert total seconds into minutes. This is a simple case of storing the output from a maths equations to convert seconds to minutes.
- Round up your mins - Using your stored mins, this becomes a simple 'round' call on the mins you stored.
Hope that's of use. (I suspect I'm too late and you've long since completed it.) :)