Lesson 1 of 0
In Progress

Adding Days to a Given Date

Kedeisha June 16, 2023

Write a Python function that accepts a string representing a date and an integer representing a number of days, and returns a new date that is the original date plus the number of days. Assume the date string is in the format ‘YYYY-MM-DD’.

Input Data: Your function should accept a string representing a date and an integer representing a number of days.

Explanation of Solution: The function add_days uses strptime to convert the date string to a datetime object. It then creates a timedelta object representing the specified number of days, and adds this to the original date. The strftime function is used to format the resulting datetime object as a string.