Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Dates and Times in Python 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