
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Find yesterday’s, today’s and tomorrow’s date in Python
When it is required to find yesterday, today and tomorrow’s date with respect to current date, the current time is determined, and a method is used (in built) that helps find previous day and next day’s dates.
Below is a demonstration of the same −
Example
from datetime import datetime, timedelta present = datetime.now() yesterday = present - timedelta(1) tomorrow = present + timedelta(1) print("Yesterday was :") print(yesterday.strftime('%d-%m-%Y')) print("Today is :") print(present.strftime('%d-%m-%Y')) print("Tomorrow would be :") print(tomorrow.strftime('%d-%m-%Y'))
Output
Yesterday was : 05-04-2021 Today is : 06-04-2021 Tomorrow would be : 07-04-2021
Explanation
The required packages are imported into the environment.
The current date is determined using the ‘now’ method present in ‘datetime’ package.
It is assigned to a variable.
The ‘timedelta’ method is used to find the previous or next days, by passing the number as parameter.
When the next day has to be found, the function is added.
When the previous day has to be found, the function is subtracted.
The output is displayed on the console.
- Related Articles
- Print dates of today, yesterday and tomorrow using Numpy
- How to select yesterday's date in MySQL?
- How to get today's date in Java8?
- How to subtract date from today's date in JavaScript?
- Get today's date in (YYYY-MM-DD) format in MySQL?
- SELECT MySQL rows where today's date is between two DATE columns?
- How to return today's records using DATE from DATETIME Field?
- Get the Day of the Week from Today's Date in Java
- How to find only Monday's date with Python?
- How water harvesting is useful in today's scenario?
- Cyber Security Risks in today's Era of Digitalization
- Getting tomorrow and day after tomorrow date in JavaScript
- Segregate 0’s and 1’s in an array list using Python?
- Difference between char s[] and char *s in C
- What is the role of multifaceted counselling in today's world?
- Sort an arrays of 0’s, 1’s and 2’s using C++

Advertisements