How to Get Yesterday Date in Python?
Published On: 01/06/2022 | Category:
Python
Hi Dev,
I will show you an example of how to get yesterday's date in python. This article goes into detail on how to get yesterday's date in python by date. I would like to show you how to get yesterday's date in python and timestamp. This tutorial will give you a simple example of how to get yesterday's date in python as a date. Let's see below example of how to get yesterday's date in python as DateTime.
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-31
It will help you....