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

Aleksandar Stankovic
Aleksandar Stankovic
Python Development Techdegree Student 9,648 Points

What am I missing out here?

Hello guys, I tried my code in my own editor, and it works just fine, but here I get the answer to "try again". Is there something that I am missing?

Thanks for the response!

def minutes(datetime1,datetime2):
    return round(datetime.timedelta(seconds=datetime2-datetime1).total_seconds()/60)

2 Answers

Jason Anders
Jason Anders
Treehouse Moderator 145,526 Points

Hi Aleksandar Stankovic

You seem to be on the right track, with just a couple corrections needed.

First, you can't declare a variable within the parameters of a method call, nor do you need to, so that part will need to be deleted. (seconds=datetime2-datetime1) should only be (datetime2-datetime1).
Second, datetime.timedelta doesn't actually take any parameters, but instead, should have the .total_seconds() method called on it directly, and those parameters should be inside of the .total_seconds() method call.

So, with the exceptions of the "seconds" variable that can't be there, you have everything there. With the above hints, I believe you should be able to refactor the code to pass.

Keep Coding! :) :dizzy: