This course will be retired on May 14, 2024. We recommend "Python Dates and Times" for up-to-date content.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
We'll just dive in and start tweaking dates and times to our liking.
Here are the datetime docs
Examples
>>> import datetime
>>> now = datetime.datetime.now()
>>> morning = now.replace(hour=9, minute=0)
The above will make a variable now
that represents now, and then change the time to 9 a.m. in the variable morning
.
>>> datetime.datetime(2014, 10) - datetime.datetime(2014, 9)
The above will give back a datetime.timedelta
object.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up