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

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

problems with minutes.py

i am having problem understanding what the question is asking from me

minutes.py
import datetime 

def minutes(datetime, datedelta):
    timedelta.total_seconds()

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

First thing first, the TWO arguments to this function are 2 datetime values, you should name 'em dt1, dt2 sth like that to avoid naming confusion to people reading the code.

You're correct in using the timedelta.total_seconds() to tackle this problem.

The important things here is that timedelta should be the difference between dt1 and dt2. Hence -> (dt2-dt1).total_seconds(), this operation will return the value in seconds. The challenge wants you to convert it into mins and rounded.

def minutes(dt1, dt2):
    return round((dt2-dt1).total_seconds()/60)

Hope it helps.