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 trialRyan Carson
23,287 PointsStuck 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!
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
42,016 Pointsthe 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
Kenneth Love
Treehouse Guest TeacherThe 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?
Ryan Carson
23,287 PointsRyan Carson
23,287 PointsThanks! Stupid math mistake on my part.
Also, I didn't realize I could use
.seconds
Cheers :)
Erika Suzuki
20,299 PointsErika Suzuki
20,299 Pointsthe direction said to use
timedelta.total_seconds()
. This is wrong when copy pasted as is.