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

I don't understand the answer.

So, I got the answer to this question from another Help thread. What I don't understand is how I was supposed to reach it. It said to take an integer and return a datetime. Where's all this other stuff come from?

I feel like I'm supposed to know this, but somehow I've really been struggling with datetimes as a concept.

time_machine.py
import datetime

starter = datetime.datetime(2015, 10, 21, 16, 29)
def delorean(before_start):
    print(starter)
    jumped = starter + datetime.timedelta(hours=before_start) # + not -
    print(jumped) 
    return jumped


jumped_started = delorean(4)
print(jumped_started)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,106 Points

Hey Eric Nachtsheim, using datetime.timedelta was discussed in the video 3 of the previous section: dates-and-times-in-python-> Dates and Times-> https://teamtreehouse.com/library/time-deltas look around time 0:30.

It can be helpful to keep notes or a journal to help recall where material was taught. I found this reference by going back to the course outline and searching for timedeltas.

I often use Google: “python docs <topic>”, which led me to the timedelta section.

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

Andy Hughes
Andy Hughes
8,127 Points

For anyone finding this difficult. Me too, but then I went back to the video Kenneth did on timedelta and bam, it was right there. It's tough to remember it all and I hate having to go back through videos. But it does work.

So in this challenge, we're being asked to move the 'starter' time forward by x number of hours. So to begin with, we need to create a timedelta that is focused on (hours = however many hours we want to advance) and capture this in a variable. (This is in the video).

Once we have our timedelta, we can then create a new variable to capture the result of adding the 'starter' variable to the variable where we stored our 'timedelta'.

Then it should hopefully be a case of returning that resulting variable and printing it.