To add days to date using Python, the easiest way is to use the Python timedelta() function from the datetime module.

from datetime import timedelta, date

two_days_in_future = date.today() + timedelta(days=2)

print(date.today())
print(two_days_in_future)

#Output:
2022-02-08
2022-02-10

When working with data in Python, many times we are working with dates. Being able to manipulate and change dates easily is very important for efficient processing.

One such change is to be able to add days to a date.

With Python, we can easily add days to a date with the help of the datetime module.

To add days to a date in Python, we can use the timedelta() function from the datetime module.

Below is code that shows you how to add days to get some dates in the future using Python.

from datetime import timedelta, date

two_days_in_future = date.today() + timedelta(days=2)
ten_days_in_future = date.today() + timedelta(days=10)
one_hundred_days_in_future = date.today() + timedelta(days=100)

print(date.today())
print(two_days_in_future)
print(ten_days_in_future)
print(one_hundred_days_in_future)

#Output:
2022-02-08
2022-02-10
2022-02-18
2022-05-19

You can also use datetimes in the same way to add days to a datetime variable.

Below are some examples of adding days to datetime variables in Python.

from datetime import timedelta, datetime

now = datetime.now()

two_days_in_future = now  + timedelta(days=2)
ten_days_in_future = now  + timedelta(days=10)
one_hundred_days_in_future = now  + timedelta(days=100)

print(now)
print(two_days_in_future)
print(ten_days_in_future)
print(one_hundred_days_in_future)

#Output:
2022-02-08 09:17:59.577000
2022-02-10 09:17:59.577000
2022-02-18 09:17:59.577000
2022-05-19 09:17:59.577000

If instead you’d like to subtract days from a date in Python, you can use a very similar method as shown above but subtract the timedelta function.

Adding One Day to Get Tomorrow’s Date Using Python

We can easily get tomorrow’s date using the Python datetime module. To get tomorrow’s date, we just need to add 1 day using the timedelta() function.

Below is the Python code which will allow you to get tomorrow’s date.

from datetime import timedelta, date

tomorrow_date = date.today() - timedelta(days=1)

print(date.today())
print(tomorrow_date )

#Output:
2022-02-08
2022-02-09

How to Add Days to a Date With pandas in Python

If you are using the Python pandas module, we can add days to a date easily.

With pandas, to add days to a date, we use the DateOffset() function.

Below is an example of how to use pandas to add days to a date in Python.

import pandas as pd

startdate = "01/29/2022"
enddate = pd.to_datetime(startdate) + pd.DateOffset(days=5)

print(startdate)
print(enddate)

#Output:
2022-01-29 00:00:00
2022-02-03 00:00:00

Hopefully this article has been beneficial for you to learn how to add days to a date using Python.

Categorized in:

Python,

Last Update: February 26, 2024