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 Simple Time Machine

time_machine.py

Please assist me with this challenge, is there an other way to solve it... do I have to go through if, elif, converting min, hours... into datetime format one by one, or is there more officiant way?

time_machine.py
import datetime

starter = datetime.datetime(2015, 10, 21, 16, 29)

def delorean(int_time):
  new_time = datetime.datetime.fromtimestamp(int_time)
  return datetime.datetime.combine(starter, new_time)

2 Answers

Stephen Bone
Stephen Bone
12,359 Points

Hi Christine

Apologies if I'm covering something that hasn't been discussed yet as it's been a little while since I looked at this stage but assuming you've covered timedelta's you could do something like below:

import datetime

starter = datetime.datetime(2015, 10, 21, 16, 29)

def delorean(num):
  return starter + datetime.timedelta(hours=num)

Hope it helps!

Stephen

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You're not going to get a timestamp as the argument to delorean, you're going to get a number. Use that number to advance starter by that many hours. For example, if the number is 5, return a datetime that is starter plus 5 hours.