Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Dates and Times in Python Dates and Times Today and Tomorrow

Sahar Nasiri
Sahar Nasiri
7,454 Points

Timedelta.minute

Timedeltas do not have a .minute property Timedeltas do have a .second property.

I tested timedelta.minute and it does work!

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,064 Points

According to the timedelta docs

A timedelta can be specified using class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

One created, timedelta all argument values are converted the three attributes:

Instance attributes (read-only):

Attribute      Value
days           Between -999999999 and 999999999 inclusive
seconds        Between 0 and 86399 inclusive
microseconds   Between 0 and 999999 inclusive

And has the instance attribute:

timedelta.total_seconds()
Return the total number of seconds contained in the duration. Equivalent to td / timedelta(seconds=1).

So to get the number of minutes use int(datetime.timedelta.total_seconds() / 60)