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

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,868 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

wow! I didn't realize it was that simple!

my code was saying it wasn't returning the right value, what's going on?

def timestamp_oldest(*args):

timestamps = []

for ts in range(0, len(args)):

    timestamps.append(ts)

return datetime.datetime.fromtimestamp(min(timestamps))