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

What's missing for this minutes.py code challenge?

I tried to take 2 time snapshots of "now" at a and b. Since there wasn't much change in minutes, I added 5 minutes to b just to see num_minutes would return a nonzero value. I took the time_delta of b-a in seconds -> converted to minutes by dividing by 60 -> and rounded using "round".

minutes.py
import datetime

def minutes():
    a = datetime.datetime.now()
    b = datetime.datetime.now() + datetime.timedelta(minutes=5)
    timedelta = b-a
    num_minutes = round(timedelta.total_seconds() / 60)
    return num_minutes

2 Answers

Hey michellewong5 you are not too far off here What we want to do is create a function with 2 arguments that will be datetimes. We can just call them a and b accordingly. def minutes(a, b): Then we want to subtract the smaller number from the larger as you have done it. timedelta = b-a then we can return the rounded timedelta.total_seconds()/60.

Great job on what you have done so far, there were just a few small things that needed to be changed. :) Keep up the great work and let us know if we can assist you further!

Ok, got it. Thank you Mel.