10-Nov-2021
.
Admin
Hello Friends,
Now let's see example of how to get current date minus 1 month in python. I am going to show you python get current date sub month. We will learn get current date minus a month using python.
The datetime module is supplies classes for manipulating dates and times. This article will give you example of get current date then minus a month in python.
Here I will give two for how to get current date substract month in python. I am use datetime and time module to get current date minus month. So let's see the below example:
Example 1
# current date minus a month
from datetime import datetime
from dateutil.relativedelta import relativedelta
# minus a month
currentTimeDate = datetime.now() - relativedelta(months=1)
currentTime = currentTimeDate.strftime('%Y-%m-%d')
print(currentTime)
Output:
2021-10-01
Example 2
# current date minus a month
from datetime import datetime
from dateutil.relativedelta import relativedelta
# minus number of month
currentTimeDate = datetime.now() - relativedelta(months=6)
currentTime = currentTimeDate.strftime('%Y-%m-%d')
print(currentTime)
Output:
2021-05-01
It will help you....
#Python