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

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap