Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Vincent Zamora
Vincent Zamora
3,871 Points

def timestamp_oldest(*args): ts = list(args) ts.sort(reverse=True) return datetime.datetim

Why doesn't this work?

import datetime

def timestamp_oldest(*args): ts = list(args) ts.sort(reverse=True) return datetime.datetime.fromtimestamp(ts[0].strftime('%Y-%m-%d %H:%M:%S'))

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):
    ts = list(args)
    ts.sort(reverse=True)
    return datetime.datetime.fromtimestamp(ts[0].strftime('%Y-%m-%d %H:%M:%S'))

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 66,739 Points

Hey Vincent Zamora, you are VERY clsoe. Two items to correct:

  • Since the "oldest" POSIX is the lowest, sorting will naturally put the oldest first. :point_right: remove reverse=True
  • The method datetime.datetime.fromtimestamp takes a POSIX format float by default. :point_right: remove use of strptime method (which does not exist on a float)

Post back if you need more help! Good luck!!

boi
boi
8,311 Points

You're totally off track here, Vincent. I could give you some direction, do this;

1) Since the number of arguments is not known, create a list and append all the arguments that will come in.

2) The challenge wants you to return the oldest POSIX date, meaning the date closest to 1970, 01, 01, so if the sort() method is used on a list, the sort() method will sort the values in the list from smallest to greatest, so the smallest or oldest value will be the first value in the list.

3) Return the smallest value in the list by using datetime.datetime.fromtimestamp() method.

If you need help, msg me here.