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 Let's Build a Timed Quiz App Timestamp Ordering

Christopher Wommack
Christopher Wommack
3,983 Points

Timestamp Oldest

What do I have wrong?

# If you need help, look up datetime.datetime.fromtimestamp()
# Also, remember that you *will not* know how many timestamps
# are coming in.
import datetime

def timestamp_oldest(*args):
    for ea in args:
    return datetime.datetime.fromtimestamp(time_stamps[1])

2 Answers

Robin Goyal
Robin Goyal
4,582 Points

Since you're sorting with the condition that reverse = True, then your list of timestamps will have the newest one at the front of the list and the oldest timestamp at the end of the list. You're indexing at the second item of the list instead of the last item. To choose the last item, use an index of -1.

Luis Vasquez
Luis Vasquez
21,347 Points

import datetime

def timestamp_oldest(*args): times = sorted([*args]) return datetime.datetime.fromtimestamp(times[0])