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

Rounding minutes comes back as incorrect.

Not sure what I'm doing wrong. It would help if I could see the input.

minutes.py
def minutes(datetime1, datetime2):
  return round(datetime2.minute - datetime1.minute)

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You're not doing what you think you're doing here.

Let's pretend datetime1 is yesterday at 1:30pm. Let's also pretend that datetime2 is tomorrow at 1:40pm. You code subtracts the minutes of datetime2 from the minutes of datetime1, which would be 10 minutes. But are there actually only 10 minutes between those two datetimes?

You need to get the timedelta that represents the time between the two datetimes. Then round the minutes of that timedelta...except timedeltas don't have minutes. But they do have seconds! How would you get from seconds to minutes?

Inconceivable!

Thank you for the help! I had a feeling it had something to do with timedeltas, but I couldn't find an example that looked similar to my problem. I'll have to go deeper.