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 trialadityaarakeri
10,653 PointsDates and Times challenge task
Got the wrong number of minutes. Expected 1507, got 5424300.0. Please help me solve this task
import datetime
def minutes(d1, d2):
r = d1 - d2
result = r.total_seconds() * 60
return result
d1 = datetime.datetime.now()
d2 = datetime.datetime.now()
minutes(d1,d2)
2 Answers
Mike Wagner
23,559 PointsTo get minutes from seconds you need to divide since there are 60 seconds in a minute. You'll probably need some version of a round() or to cast to an int explicitly, also, to remove any partial minute value otherwise, you'll probably get something like 1506.7 or 1507.3 which would still fail, based on the response it gave
adityaarakeri
10,653 Points@Mike Wagner: Thank you for the answer. I was able to clear the challenge by the below code.
import datetime
import math
def minutes(d1, d2):
r = d1 - d2
result = math.ceil( r.total_seconds() / 60 )
return result
d1 = datetime.datetime.now()
d2 = datetime.datetime.now()
minutes(d1,d2)