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

Maximilian Richly
Maximilian Richly
4,872 Points

not sure what I'm doing wrong

help, why is this not working??

minutes.py
import datetime

def minutes(dt1, dt2):
    minutes = (dt2.seconds() - dt1.seconds()) / 60
    return minutes

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Maximilian - The challenge is asking you to use timedelta.total_seconds() to get the number of seconds. So start by the subtracting the datetimes to get a timedelta and then call total_seconds() on that. Finally, after dividing by 60 pass the result to the round() function and return it.

Maximilian Richly
Maximilian Richly
4,872 Points

I tried that, but I'm still having trouble getting it to work. Can you give me an example of the right code?

Kourosh Raeen
Kourosh Raeen
23,733 Points

Can you post your modified code?