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 trialMUZ140057 Dumisani Nyamusa
8,029 Pointsdate and times
Create a new variable called two that holds the value of now with the hour set to 14. Use the .replace() method
import datetime
dir(datetime)
now=datetime.datetime.now()
3 Answers
Kenneth Love
Treehouse Guest TeacherOK, you have now
set to .now()
, but you need to do the rest of prompt and change the hour to 14.
MUZ141095 Kelvin Chawora
9,348 PointsSince you have declared now as a variable that holds the outcome of datetime.datetime.now(), whenever you need to use datetime.datetime.now(), use now() instead. The .replace() method is being used to change/set the value of hour to a new entity, that is, 14. Therefore, .replace() is functioning within the now() variable.
This is what you should end up with:
import datetime
now = (datetime.datetime.now())
two = now.replace(hour=14)
Jose Luis Lopez
19,179 Pointsimport datetime
now = datetime.datetime.now()
two = now.replace(hour=14)
Chris White
6,212 PointsChris White
6,212 PointsI'm totally stuck on the next step. Here's what I've got:
import datetime
now = datetime.datetime.now()
two = now.hour.replace(14)
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherYou want
now.replace(hour=14)
instead of what you have.Chris White
6,212 PointsChris White
6,212 PointsThanks, Kenneth, that totally worked. Is there a simple reason that we can access those things via dot notation but in this instance needed to use replace in that manner?
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherThey're read-only. You have to use
.replace()
to write to them.