Python Dates and Times in Python Let's Build a Timed Quiz App Simple Time Machine

Dolorean function, how to add hours to a datetime

the answer is probably simple, I might have to review the previous section.

Any suggestions?

time_machine.py
import datetime

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

def delorean(int):
    return starter.hour + int

2 Answers

Pete P
Pete P
7,612 Points

What you're currently returning is just the value of hour from starter increased by the int. But, you need to return an entire datetime that's hour has been increased by int.

Time can be added to a datetime using datetime.timedelta

Try it out and answer back if you're still stuck.

Goodluck!

Thanks a lot!