Thursday 23 September 2021

Python: Increase date by n days

Below snippet is used to increase the date by n days.

new_date = input_date + timedelta(days_to_increase)

 

Find the below working application.

 

increase_date_by_n.py

from datetime import datetime, timedelta

def increase_date_by_n_days(input_date, days_to_increase):
    new_date = input_date + timedelta(days_to_increase)
    return new_date

input_date = datetime(1988, 6, 6)
new_date = increase_date_by_n_days(input_date, 5)

print('input_date -> ', input_date)
print('new_date -> ', new_date)

Output

input_date ->  1988-06-06 00:00:00
new_date ->  1988-06-11 00:00:00



 

Previous                                                    Next                                                    Home

No comments:

Post a Comment