Python Get Yesterday Date Example


Share:
 | Published By: Admin | Published On: May 28, 2022 | Category: Python


Hi Dev,

In this example, you will learn how to get yesterday date in python. you will learn how to get yesterday date in python as date. if you have question about how to get yesterday date in python as datetime then I will give simple example with solution. We will use how to get yesterday date in python by date.

We will work with data objects by importing the module datetime and timedelta to work with dates.

timedelta class from datetime module helps to find the previous day date and next day date.

So let's see bellow example:

Example
# import datetime module
from datetime import datetime,timedelta

yesterday = datetime.now() - timedelta(days=1)
yDate = yesterday.strftime('%Y-%m-%d')

print('Yesterday Date Is = ',yDate)
Output:
('Yesterday Date Is = ', '2022-05-27')

It will help you....

Share: