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

Pranshu Mittal
Pranshu Mittal
4,276 Points

I am not able to identify the error in my code

I am getting the desired output when i run the same code in Jupyter Notebook, but here it says Try Again! Could anyone tell me what is the problem with my code?

minutes.py
import datetime

def minutes():
    now = datetime.datetime.now()
    today = datetime.datetime.today() - datetime.timedelta(hours = 5)
    timediff = now - today
    seconds = datetime.timedelta.total_seconds(timediff)
    total_diff = round(seconds/60)
    return total_diff

1 Answer

Steven Parker
Steven Parker
229,786 Points

Where the instructions say "Write a function named minutes that takes two datetimes...", they mean that the function needs to have two parameters and the caller will be providing both values as arguments.

The comparison needs to be done on the passed parameters and you won't need to sample the current time/date at all.

Pranshu Mittal
Pranshu Mittal
4,276 Points

Yeah i figured it out after sometime. Anyways..Thank you so much!

Steven Parker
Steven Parker
229,786 Points

Pranshu Mittal — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!