Python Dates and Times in Python Dates and Times Timedelta Minute

Amelia Nakimuli
Amelia Nakimuli
5,743 Points

Understanding the question

I'm not sure if I understand the question. Am I on the right track?
import datetime

def minutes(x, y):
    final = x - y
    secs = final.timedelta.total_seconds()
    ans = secs%60
    return ans

1 Answer

Steven Parker
Steven Parker
204,009 Points

You have the right idea, but a few issues:

  • the instructions say "You'll need to subtract the first from the second." (so switch the order)
  • "final" is a timedelta, so you can access the "total_seconds" method on it directly
  • to get minutes, you need to divide seconds by 60 (not get remainder)
  • the instructions also say to round the result