Python Dates and Times in Python Dates and Times Timedelta Minute

Kay Pengelly
Kay Pengelly
5,836 Points

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)
Kay Pengelly
Kay Pengelly
5,836 Points

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

Kay Pengelly
Kay Pengelly
5,836 Points

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!