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

Timedelta Minute Challenge

Hi there,

I'm struggling with my code and I'm not sure what i'm doing incorrectly. The error message just says "Bummer: Try Again!" so I'm not sure what exactly is going wrong.

Any help would be appreciated!

Thanks Kay

minutes.py
import datetime

def minutes(dt1, dt2):
    dt1_seconds = dt1.timedelta.total_seconds()
    dt2_seconds = dt2.timedelta.total_seconds()
    return round(dt2_seconds - dt1_seconds/60)

Hi all,

I looked through some other examples and I found that Steven Parker's commentary at the below link helped: https://teamtreehouse.com/community/i-need-help-with-the-timedelta-minute-challenge

the correct code looked like the below:

def minutes (dt1, dt2):
    difference = dt2 - dt1
    return round(difference.total_seconds()/60)

I was getting confused and trying to extract a timedelta from both datetimes. A timedelta is the DIFFERENCE between two datetimes, so while the datetimes didn't have a total_seconds attribute, the variable "difference" did

Hope this helps others!

1 Answer

Hi all,

I looked through some other examples and I found that Steven Parker's commentary at the below link helped: https://teamtreehouse.com/community/i-need-help-with-the-timedelta-minute-challenge

the correct code looked like the below:

def minutes (dt1, dt2):
    difference = dt2 - dt1
    return round(difference.total_seconds()/60)

I was getting confused and trying to extract a timedelta from both datetimes. A timedelta is the DIFFERENCE between two datetimes, so while the datetimes didn't have a total_seconds attribute, the variable "difference" did

Hope this helps others!