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

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

minutes.py
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
    else:
        print("time2 has to be greater than time1")

3 Answers

Phil Livermore
Phil Livermore
11,018 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,018 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.