Python Dates and Times in Python Let's Build a Timed Quiz App Timestamp Ordering

Create a function named timestamp_oldest that takes any number ofPOSIX timestamp arguments.

I am getting 'Try again' error...Where am i getting it 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 random
import datetime
def timestamp_oldest(args):
  oldest = datetime.datetime.now()
  for arg in args:
    oldest > datetime.datetime.fromtimestamp(arg)

return oldest

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,837 Points

Hi, Natasha Hove

Create a function named timestamp_oldest that takes any number of POSIX timestamp arguments. Return the oldest one as a datetime object.

  1. to convert a POSIX timestamp to datetime object, we can make use of the datetime.datetime.fromtimestamp() method from datetime module, which you got it right.
  2. then, this function accepts ANY number of arguments, and stores them in the *args tuple, the challenge gave you a hint here

Remember, POSIX timestamps are floats and lists have a .sort() method.

But the easiest way to pick out the oldest POSIX timestamp from the tuple is using min() method.

To put everything together.

import datetime

def timestamp_oldest(*args):
  return datetime.datetime.fromtimestamp(min(args))

Hope this helps.

Adam Teale
Adam Teale
10,989 Points

That's cool! Thanks for sharing