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.

Kirome Thompson
5,350 PointsWrite a function named delorean that takes an integer. Return a datetime that is that many hours ahead from starter.
my output is getting this:
Bummer: delorean
didn't return the right datetime. Got 2015-10-21 05:29:00.
can't see where I'm getting this wrong everything is changing except the hours :(
Thanks in advanced
import datetime
starter = datetime.datetime(2015, 10, 21, 16, 29)
def delorean(ahead):
return starter.replace(hour=ahead)
2 Answers

Steven Parker
221,329 PointsYou're close, but instead of simply replacing the hour with the argument, you need to add the argument to the current hour:
return starter.replace(hour=starter.hour+ahead)

Michael Ford
3,432 PointsHere is my solution using timedelta:
def delorean(value): return starter + datetime.timedelta(hours=value)
starter = datetime.datetime(2015, 10, 21, 16, 29)
Kirome Thompson
5,350 PointsKirome Thompson
5,350 PointsThanks very much Steven Parker it worked, I see the different in code length but not in practicality to me it reads the same. would you be able to explain the difference??
Thanks in advance
Kirome Thompson
5,350 PointsKirome Thompson
5,350 Pointsno worries I misread your comment thanks appreciate the help
Adrian Torrente Tenreiro
12,540 PointsAdrian Torrente Tenreiro
12,540 Pointscan we not use a timedelta?