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 trialSahar Nasiri
7,454 PointsWhat is wrong with this code?
import datetime
def minutes(t_1, t_2):
return t_1.minute - t_2.minute
2 Answers
Steven Parker
231,248 PointsHere's a few hints:
- Remember, the challenge said: "You'll need to subtract the first from the second."
- When you subtract two datetimes, you get a timedelta. Timedeltas do not have a .minute property
- Timedeltas do have a .second property.
- Also remember the challenge said that the function: "...returns the number of minutes, rounded..."
Take these into account and I bet you can solve it.
Sahar Nasiri
7,454 PointsI have tested my code in python shell too. timedelta does have a minute property. I don't still know what is wrong with my code?
Stefan Vaziri
17,453 PointsThis worked for me:
import datetime
def minutes(dt1, dt2): difference = dt2 - dt1 second = difference.total_seconds() minutes = second/60 return round(minutes)
Sahar Nasiri
7,454 PointsSahar Nasiri
7,454 PointsPlease help me more! I cannot pass this challenge because I don't know why I can't use timedelta.minute when it is working?
Sahar Nasiri
7,454 PointsSahar Nasiri
7,454 Pointsdef minutes(t1, t2): t = t2 - t1 return t.year* 518400 + t.month*43200 + t.day*1440 + t.hour*60 + t.minute
Is it right? I don't know why I'm doing this :))