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

Vincent Zamora
Vincent Zamora
3,872 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 68,423 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
14,241 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.