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.
Eric Nachtsheim1,993 Points
I'm stuck (Dates and Times in Python, Timedelta-minute)
I can't seem to figure out what I'm doing wrong. I think I don't understand timedelta well enough.
Below is what I've come up with, and the only error message I get from it is "Try again". I've tried a number of different variants, but I'm just baffled. Any help would be appreciated.
import datetime def minutes(datetime1, datetime2): datetime1 = datetime.datetime.now() datetime2 = datetime.datetime.today() seconds = datetime2.second - datetime1.second total = datetime.timedelta.total_seconds(seconds) minutes = round(total / 60) return minutes
Chris FreemanTreehouse Moderator 67,464 Points
Hey Eric Nachtsheim, you are not far off.
- The assignments to
datetime2create new local references that override the arguments passed in. Remove these assignments
datetimeobject does have a seconds attribute. The refers to the number of partial minutes in
- subtracting two
datetimeobjects creates a timedelta object. so,
seconds = datetime2 - datetime1. "seconds" might not be the best variable name
- It is this
timedeltaobject that has the
total = seconds.total_seconds()
The rest flows correctly.
Post back if you need more help. Good luck!!