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) 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
24,587 Points

import datetime

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