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 trialCross Ender
9,567 PointsI can't think of an obvious answer.
Can't figure this out.
import datetime
def minutes(dt1, dt2):
m1 = datetime.timedelta.total_seconds(dt1.minute)
m2 = datetime.timedelta.total_seconds(dt2.minute)
return round(m2 - m1)
1 Answer
Steven Parker
231,269 PointsIf the answer was obvious it wouldn't be much of a "challenge".
But seriously, it's easier than you think. Remember that when you subtract one datetime from another that the result is a timedelta. There's no method to get minutes directly but as the challenge suggested, you could use the total_seconds method. Then it's just a matter of a little math to account for 60 seconds in a minute and then some rounding.