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

Need help with minutes.py

Need help here substracting two datetimes to find the difference in seconds and then return the total minutes, rounded.

minutes.py
from datetime import datetime

def minutes(time1, time2):
    timedelta = time1.seconds - time2.seconds
    return round(timedelta / 60)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Taylor Fritz! Looks like you're doing well and you have the basic idea. But there's a couple of things going on here. First, you want to subtract time1 from time2, not the other way around. You can do that directly which then gives you a timedelta. And you can use that to get the total_seconds(). So if I change that middle line from this:

timedelta = time1.seconds - time2.seconds

To this:

timedelta = (time2 - time1).total_seconds()

Then we get the result we're after. The rounding and division part is spot on!

Hope this helps! :sparkles:

Jennifer Nordell THANK YOU SO MUCH! I have been so stumped on that!! Haha