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

Pitrov Secondary
Pitrov Secondary
5,121 Points

How do I round time minutes?

It says I have to round the minutes. I do not know how to, please help me!

Thanks!

minutes.py
import datetime

def minutes(time1, time2):
    if time1.timedelta.total_seconds() > time2.timedelta.total_seconds():

1 Answer

Oskar Lundberg
Oskar Lundberg
9,534 Points

Hey there! Here is my solution to the challenge, hope it helps :D

import datetime

def minutes(time1, time2):
    difference = time2 - time1 # Creates a timedelta
    diff_seconds = difference.total_seconds() # calls the total_second() function on the timedelta to get the total seconds.
    diff_minutes = diff_seconds / 60 # divides the seconds by 60, to get the total minutes.
    return round(diff_minutes) # rounds the minutes to get a whole number. (and returns it)