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

Python: timedelta-minute challenge

I don't know what am i doing wrong? Can you help me, please?

The challenge task is this one:

Write a function named minutes that takes two datetimes and, using timedelta.total_seconds() to get the number of seconds, returns the number of minutes, rounded, between them. The first will always be older and the second newer. You'll need to subtract the first from the second.

minutes.py
from datetime import timedelta

def minutes(datetime1, datetime2):
    number_of_seconds = datetime2.total_seconds() - datetime1.total_seconds()
    minutes = round(number_of_seconds/60)
    return minutes
Michael Revy
Michael Revy
3,882 Points

I am new, but datetime has no method total_seconds() ??. datetimes can be added or subtracted - tricky part is then expressing what you want - hours, days etc etc. I think the below shoud work for def minutes.

return (datetime2 - datetime1)/timedelta(minutes=1)

Hello,

Thank you Michael for taking from your time to answer my question. I managed to complete the challenge without the total_second() function. I just substracted datetime2 from datetime1, then the result divided by 60, and the last step was to return the rounded total. Your solution is also good.

Have a good day!