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 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.