- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to subtract Python timedelta from date in Python?
You can subtract a day from a python date using the timedelta object. You need to create a timedelta object with the amount of time you want to subtract. Then subtract it from the date.
from datetime import datetime from datetime import timedelta today = datetime.today() yesterday = today - timedelta(days=1) print(today) print() print(yesterday)
This will give the output −
2017-12-29 12:28:06.531791 2017-12-28 12:28:06.531791
You can also subtract years, months, hours, etc. in the same way from a date using the timedelta object.
- How can I subtract a day from a Python date?
- Java Program to subtract year from current date
- Java Program to subtract week from current date
- Python Pandas - Return the microseconds from Timedelta object
- Python Pandas - Return the nanoseconds from Timedelta object
- Python Pandas - Return the seconds from Timedelta object
- Subtract one Chebyshev series from another in Python
- Subtract one Hermite series from another in Python
- Subtract one Laguerre series from another in Python
- Subtract one Legendre series from another in Python
- Subtract one Hermite_e series from another in Python
- How to subtract number of days from a date to get the previous date in R?