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?

timestamp.py
# 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):
    time_stamps=[]
    for ea in args:
        time_stamps.append(ea)
    time_stamps.sort(reverse=True)
    return datetime.datetime.fromtimestamp(time_stamps[1])

2 Answers

Robin Goyal
Robin Goyal
4,581 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,093 Points

import datetime

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