How To Add Days Date In Python?

23-Dec-2021

.

Admin

How To Add Days Date In Python?

Hello Friends,

Now let's see example of how to get add days from current date day in python. I am going to show you python date to add days example. We will learn add days in date using python.

The datetime module is supplies classes for manipulating dates and times. This article will give you example of how to add days to dates in python.

Here I will give an example for how to add days to date in python. I am use datetime and time module to add days date. So let's see the below example:

Example : 1


example1.py

# import datetime module

from datetime import datetime,timedelta

currentTimeDate = datetime.now() + timedelta(10)

currentTime = currentTimeDate.strftime('%Y-%m-%d')

print(currentTime)

Run Example

python example1.py

Output:

2021-12-28

Example : 2

example2.py

# import datetime module

from datetime import timedelta, date

currentTimeDate = date.today() + timedelta(5)

currentTime = currentTimeDate.strftime('%Y-%m-%d')

print(currentTime)

Run Example

python example2.py

Output:

2021-12-23

Example : 3

example3.py

# import pandas module

import pandas as pd

my_date = "2021-12-18"

res_date = pd.to_datetime(my_date) + pd.DateOffset(days=3)

print(res_date)

Run Example

python example3.py

Output:

2021-12-21 00:00:00

It will help you....

#Python