Sometimes, we want to subtract a day from a date with Python.
In this article, we’ll look at how to subtract a day from a date with Python.
How to subtract a day from a date with Python?
To subtract a day from a date with Python, we can use a timedelta object.
For instance, we write
from datetime import datetime, timedelta
d = datetime.today() - timedelta(days=days_to_subtract)
to subtract days_to_subtract days from today by creating a timedelta object with timedelta and then subtracting that from datetime.today().
Conclusion
To subtract a day from a date with Python, we can use a timedelta object.