How to Add Days to Date in Python?
This article will give you example of python add days to date example. this example will help you how to add days to date in python. In this article, we will implement a python add days to date in dataframe. This article goes in detailed on python add 1 day to date string.
In this example, I will give two examples for you of how to add days to date in python and how to add days to today's date in python. therefore, let's see below example code and try it.
Example 1: Python Add Days to Date String
main.py
from datetime import datetime from datetime import timedelta myDateString = "2022-06-01" myDate = datetime.strptime(myDateString, "%Y-%m-%d") newDate = myDate + timedelta(days=5) print("Old Date :") print(myDate) print("New Date :") print(newDate)
Output:
Old Date : 2022-06-01 00:00:00 New Date : 2022-06-06 00:00:00
Example 2:
main.py
from datetime import datetime from datetime import timedelta myDate = datetime.today() newDate = myDate + timedelta(days=5) print("Old Date :") print(myDate) print("New Date :") print(newDate)
Output:
Old Date : 2022-06-09 19:31:21.200141 New Date : 2022-06-14 19:31:21.200141
I hope it can help you...