
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 can I subtract a day from a Python date?
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.
example
from datetime import datetime from datetime import timedelta today = datetime.today() yesterday = today - timedelta(days=1) print(today) print() print(yesterday)
Output
This will give the output −
2017-12-29 12:28:06.531791 2017-12-28 12:28:06.531791
- Related Questions & Answers
- How do I subtract minutes from a date in JavaScript?
- How can I subtract tuple of tuples from a tuple in Python?
- How to subtract Python timedelta from date in Python?
- How to subtract days from a date in JavaScript?
- How do I subtract one week from this date in JavaScript?
- How can we fetch month and day from a given date in MySQL?
- How can I select date from a datepicker div using Selenium Webdriver?
- How to subtract date from today's date in JavaScript?
- How can I source a Python file from another Python file?
- How to subtract number of days from a date to get the previous date in R?
- How to subtract seconds from all the date records in a MySQL column?
- How to get a Date from year, month and day in Java?
- Is there a way to subtract number of days from a date in MySQL?
- Java Program to subtract week from current date
- Java Program to subtract year from current date
Advertisements