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 trial

Python Dates and Times in Python (2014) Dates and Times Timedelta Minute

timedelta minuite

What I'm doing wrong here? can anyone please tell me what this 'round' does ??

minutes.py
import datetime
def minutes(datetime1,datetime2):
    datetime1 = datetime.timedelta.total_seconds(datetime1)
    datetime2 = datetime.timedelta.total_seconds(datetime2)
    diff_in_min = (datetime1 - datetime2)/60
    return round(diff_in_min)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You are on the right track, here are some hints:

  • be mindful when subtracting. datetime2 is the β€œlater” time and therefore has the larger epoch time
  • the total_seconds method is only available on the timedelta object: (datetime2 - datetime1)

    • πŸ‘‰ (datetime2 - datetime1).total_seconds() is legal syntax but you may wish to assign the subtraction to a variable, then call the method on that variable.
  • the first and second statements reassigning datetime1 and datetime2 are not necessary. (I commented them out

Post back if you need more help. Good luck!!!

Thank you for the response. It helped me to solve the problem.