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 trialUnashe Mutambashora
3,433 PointsConverting 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
else:
print("time2 has to be greater than time1")
3 Answers
Phil Livermore
11,018 PointsYour 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.
Unashe Mutambashora
3,433 PointsThanks Phil for the response. So calling the timedelta class is not always required when trying to add/subtract time?
Phil Livermore
11,018 PointsNot 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.