Python Get Current Date Minus 1 Year

Python

Nicesnippets

649

01-11-2021


Python Get Current Date Minus 1 Year

Hello Friends,

Now let's see example of how to get current date minus 1 year in python. I am going to show you python get current date sub year. We will learn get current date minus a year 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 year in python.

Here I will give two example for how to get current date substract year in python. I am use datetime and time module to get current date minus year. So let's see the below example:

Example 1


# current date minus a year

from datetime import datetime

from dateutil.relativedelta import relativedelta

# minus 1 year

currentTimeDate = datetime.now() - relativedelta(years=1)

currentTime = currentTimeDate.strftime('%Y')

print(currentTime)

Example 2

# current date minus a year

from datetime import datetime

from dateutil.relativedelta import relativedelta

# minus number of year

currentTimeDate = datetime.now() - relativedelta(years=5)

currentTime = currentTimeDate.strftime('%Y')

print(currentTime)

Output:

2016

It will help you....


Recommended Posts