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

Cant figure out minute delta question!

I'm calculating the total mins since midnight... and then subtracting the first occurring time from the second occurring time- which I thought would leave me with the delta !

Am I doing something stoopid ?

minutes.py
import datetime

def minutes(dt1, dt2):

  dt1_tot = dt1.minute + (dt1.hour*60)
  dt2_tot = dt2.minute + (dt1.hour*60)

  return dt2_tot - dt1_tot

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello David,

I am not understanding the reason behind the 2 steps you have written here. The challenge says that we are passing in 2 datetimes into the function, so we should be able to subtract one from the other. For this we would only need to focus on which datetime is the minuend and which one is the subtrahend.

This would give us the difference between the 2 in seconds, while we want minutes (/60) and the result has to be rounded.

Let me know if any other doubts!

Vittorio