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 trialAndrei Oprescu
9,547 PointsWhat am I supposed to do here?
I am confused because the wording is weird. can you help me solve this code?
import datetime
def minutes(date, date1): timedelta.total_seconds(date, date1)
Please look at the question of the quiz and tell me what I am supposed to do.
Thanks
import datetime
def minutes(date, date1):
timedelta.total_seconds(date, date1)
Andrei Oprescu
9,547 PointsMy question was:
Write a function named minutes that takes two datetimes and, using timedelta.total_seconds() to get the number of seconds, returns the number of minutes, rounded, between them. The first will always be older and the second newer. You'll need to subtract the first from the second.
Hope you can help me.
Thanks
2 Answers
David Dzsotjan
5,929 PointsOkay, then you got to define a variable that gets the returned value from timedelta.total_seconds(). This will be the number of seconds elapsed between date and date1. Then, you can define another variable, say, "minutes" that gets the value of int(seconds/60). Then, you return the variable minutes. Does this help?
David Dzsotjan
5,929 PointsSo, for example
import datetime
def minutes(date, date1):
duration = date1 - date # Create a timedelta object
seconds = duration.total_seconds() # Seconds elapsed between date1 and date
minutes = int(seconds / 60)
return minutes
Andrei Oprescu
9,547 PointsThank you! Your answer helped a lot!
David Dzsotjan
5,929 PointsYou're welcome, glad I could help :)
David Dzsotjan
5,929 PointsDavid Dzsotjan
5,929 PointsI can't see the question, but what timedelta.total_seconds() does is return the total number of seconds contained in the duration. If you need to calculate the number of minutes elapsed between date and date1, then you just need to divide the result by 60 and take the integer part of it. Hope this helps.