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

Converting seconds obtained from timedelta.total_seconds() into minutes

Hie guys. How do I do that. Cause It seems I have satisfied all the other requirements

from datetime import timedelta
from datetime import datetime

def minutes(time1, time2):
    if time2 > time1:
        time_difference = timedelta(minutes=time2) - timedelta(minutes=time1)
        return time_difference.total_seconds() / 60
        print("time2 has to be greater than time1")

3 Answers

Phil Livermore
Phil Livermore
11,017 Points

Your time difference isn't calulating correctly. You don't need timedelta, you just need to subtract time1 from time2.

You also need to round to the nearest minute.

Thanks Phil for the response. So calling the timedelta class is not always required when trying to add/subtract time?

Phil Livermore
Phil Livermore
11,017 Points

Not if you already have two datetimes. If you want to subtract/add a certain amount of time, say 1 day or 2 hours than you can use timedelta but as the values are already datetimes it is not necessary. I think the question is a bit misleading as it mentions timedelta, but I think they are hinting that you create a variable called timedelta, which you have called time_difference instead.