How to add days to a date in Python

If you have a date in Python of type datetime and you want to add certain days to the date, you can make use of the timedelta class from the same datetime module.


Let's take a look at an example:

from datetime import date, timedelta

date_today = date.today()

days_to_add = 10

new_date = date_today + timedelta(days=days_to_add)

print(f"Date after adding {days_to_add} days to {date_today} is {new_date}")
Output:
Date after adding 10 days to 2023-07-06 is 2023-07-16
Add days to date example Python

References:

  1. datetime module: https://docs.python.org/3/library/datetime.html
  2. date class: https://docs.python.org/3/library/datetime.html#date-objects
  3. timedelta class: https://docs.python.org/3/library/datetime.html#timedelta-objects
  4. date.today() method: https://docs.python.org/3/library/datetime.html#datetime.date.today

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!