From the course: Learning Python
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Using timedelta objects - Python Tutorial
From the course: Learning Python
Using timedelta objects
- [Instructor] A common scenario that pops up when working with dates and times involves performing mathematical operations on the dates and times themselves. So for example, given a particular date, you might want to calculate a date in the future or the past relative to that date or the time difference between two dates. And we can use the timedelta class in Python to help us with this. And that's what we're going to look at in this example. I've also provided a link to the documentation for timedelta objects right here. You can go look at that on your own time. I'm not going to make you read through the docs. Let's just go ahead and learn by example because that's usually a lot better. So I'm going to open up the timedeltas start example, and you can see that I've imported some packages I'm going to be using. So we've already seen the date and datetime modules. You can see I'm also importing the timedelta class from datetime. Let's go ahead and copy these and let's paste them into…