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

Trevor Wood
Trevor Wood
17,828 Points

Can someone please help me with this challenge?

I've done this challenge in workspaces and it orders them, and returns the oldest one as a datetime. But the challenge keeps on telling me it's not a datetime

I used type() to check it, it's a datetime. idk what else it wants me to do.....

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

a = datetime.datetime(2015, 10, 21, 16, 29)
b = datetime.datetime(2014, 10, 21, 16, 29)
c = datetime.datetime(2013, 10, 21, 16, 29)
d = datetime.datetime(2012, 10, 21, 16, 29)
e = datetime.datetime(2011, 10, 21, 16, 29)
f = datetime.datetime(2010, 10, 21, 16, 29)
g = datetime.datetime(2016, 10, 21, 16, 29)

def timestamp_oldest(*args):
  arg_list = list()
  for arg in args:
    arg_list.append(arg)

  arg_list.sort()
  return arg_list[0]

print(timestamp_oldest(a,b,c,d,e,f,g))

1 Answer

Trevor, sometimes the instructions are a bit confusing. You don't create the timestamps. They already exist and will be used, behind the scenes, to test your code. Try this:

import datetime

def timestamp_oldest(*args):
  plist = []
  for arg in args:
    plist.append(arg)

  plist.sort()
  return datetime.datetime.fromtimestamp(plist[0])
Trevor Wood
Trevor Wood
17,828 Points

Ah I see, the datetime I was using were different from the datetime being inserted. thanks for the help!