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

Mike Jensen
Mike Jensen
4,141 Points

I need help with the timedelta minute challenge

I do not understand why this doesn't work. Can somebody please help me here. Thank you in advance.

minutes.py
import datetime

def minutes(datetime1, datetime2):
    difference_sec = datetime2.total_seconds() - datetime1.total_seconds()
    difference_min = difference_sec / 60
    return round.difference_min

1 Answer

Steven Parker
Steven Parker
210,108 Points

A "datetime" doesn't have a "total_seconds" method. But if you subtract one "datetime" from another, the result will be a "timedelta", and those do have such a method.

Also, "round" is a function; and when you call a function you write its name and then a pair of parentheses where you can place any arguments being passed to it.

Mike Jensen
Mike Jensen
4,141 Points

Of course! Thank you. It all makes sense now :)