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

Struggling with TimeDelta Minute Challenge

Works when I run it in pycharm

minutes.py
import datetime

def minutes():
    now = datetime.datetime.now()
    future = now + datetime.timedelta(seconds=300)
    seconds_elapsed = future - now

    return round(seconds_elapsed.total_seconds()/60)

2 Answers

Ryan S
Ryan S
27,276 Points

Hi Jeremy,

Yes it may work in Pycharm, but it doesn't do what the challenge asks. It might be worth giving the instructions another read.

The challenge asks you to write a function that will take two datetime arguments. These will be the objects that you perform the calculations on. Instead, you have defined your own arbitrary datetimes that were not asked for. It doesn't mention "now" or 300 seconds from now anywhere in the challenge.

import datetime


def minutes(now, future):
    time_passed = future - now
    return round(time_passed.total_seconds()/60)

Thanks Ryan! The above worked. I keep thinking they are asking for arbitrary arguments that we supply.