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

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".

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

Mel Rumsey
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

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.