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 Timedelta Minute

write a function named minutes..timedelta

little confused here none of the videos I've seen have touched on how to do this. ty

minutes.py
import datetime

def minutes (day1, day2):
    timedelta = day2 - day1
    return abs(timedelta.total_seconds())

2 Answers

Your 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
Andy Hughes
8,479 Points

Hey 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:

  1. Import datetime - which you've done
  2. Create the function with two dates - which you've done
  3. Create a timedelta using the two dates - which you've done
  4. Get total seconds and store it for use - Think about how you stored your timedelta. Can you do the same for total seconds?
  5. Convert total seconds into minutes. This is a simple case of storing the output from a maths equations to convert seconds to minutes.
  6. 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.) :)