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

Sahar Nasiri
Sahar Nasiri
7,454 Points

Don't get the question well

I searched the fromtimestamp(), what I got is, it takes a number of seconds as a time and return the year, day,... of that time, do I get right?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Both datetime and date objects have a fromtimestamp() method that creates an object from a POSIX time value. POSIX time values are floats.

The challenge asks: Create a function named timestamp_oldest that takes any number of POSIX timestamp arguments. Return the oldest one as a datetime object. Remember, POSIX timestamps are floats and lists have a .sort() method.

Stepping through this challenge:

from datetime import datetime

# Create a function named timestamp_oldest 
# that takes any number of POSIX timestamp arguments.
# Use *args to take an arbitrary number of arguments 
def timestamp_oldest(*args):
    # Return the oldest one as a datetime object. 
    # Remember, POSIX timestamps are floats and lists have a .sort() method.
    # create a list from args
    times = list(args)
    # sort the list 
    times.sort()
    # oldest time has lowest value
    # create date time from oldest value, return it 
    return datetime.fromtimestamp(times[0])
Jordan Bester
Jordan Bester
4,752 Points

chris would you mind further explaining the Posix timestamps?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

A POSIX timestamp is a floating point number representing the number of seconds since epoch time (see time docs) – January, 1970 on many systems.