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.
Timedelta Minute Challenge
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!
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)
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!