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

Stuck on this datetime Python Code Challenge

I know I'm missing something obvious here, but I can't quite figure it out. Can someone point me in the right direction? Thanks!

minutes.py
def minutes(first_dateime, second_dateime):
    difference = first_dateime - second_dateime
    answer_in_minutes = round(difference/60)
    return answer_in_minutes

2 Answers

Stone Preston
Stone Preston
42,016 Points

the task states: You'll need to subtract the first from the second.

you are currently doing it the other way around. also, you need to access the minutes property of the difference and divide that by 60. you are currently dividing the whole difference (which is a time delta, you just want the seconds of that time delta) by 60.:

def minutes(first_dateime, second_dateime):
    #the first gets subtracted from the second
    difference = second_dateime - first_dateime
    #need to access the seconds of the difference time delta
    answer_in_minutes = round(difference.seconds/60)
    return answer_in_minutes

Thanks! Stupid math mistake on my part.

Also, I didn't realize I could use .seconds

Cheers :)

Erika Suzuki
Erika Suzuki
20,299 Points

the direction said to use timedelta.total_seconds(). This is wrong when copy pasted as is.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The second datetime is "bigger" (because it's newer) than the first. How do you find the difference between two numbers? Which one goes first, the bigger or the smaller?