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

Time-Stuck...

Can someone please help me with this challenge? I can't seem to make head-ways with this no matter how I try it...

minutes.py
import datetime


time_record_1 = datetime.datetime.today() - datetime.timedelta(hours=2)
time_record_2 = datetime.datetime.today()

def minutes(time_record_1, time_record_2):
    time_diff = time_record_2 - time_record_1
    print(datetime.timedelta.total_seconds(time_diff))

1 Answer

Steven Parker
Steven Parker
229,732 Points

:point_right: It looks like you have three issues:

  • The challenge asked for the result in minutes, not seconds (you'll need to convert)
  • The challenge also asked for the result to be rounded
  • You need to return the result, not print it

Also, while it doesn't hurt anything, the two variables you defined above the function are not used (and not necessary).

Hi Steven. Thank you for helping out.

I attempted to convert the seconds to minutes by dividing the hours by dividing the seconds by 60, rounding by using the .round() function, and replacing print() with return. However I do not get the right answer. Do you have any other tips to improve this?

Thank you

import datetime


time_record_1 = datetime.datetime.today() - datetime.timedelta(days=63)
time_record_2 = datetime.datetime.today()

def minutes(time_record_1, time_record_2):
    time_diff = time_record_2 - time_record_1
    time_diff_min = (datetime.timedelta.total_seconds(time_diff)) / 60
    return time_diff_min.round(0)