Add Days to Date
Add Days to Date
Tags: Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes a date string in the format "YYYY-MM-DD" and an integer number of days to add. The function should return a new date string in the same format after adding the specified number of days. This problem is designed to help you practice date arithmetic
. The function should accept two parameters and return the new date as a string.
Constraints:
- The input date will be a
string
in the format "YYYY-MM-DD". - The number of days to add will be an
integer
(positive or negative). - The function should
return
astring
representing the new date in the format "YYYY-MM-DD". - Use the
datetime
module.
Example:
- Input:
"2023-10-05", 5
- Output: `"2023-10-10"
Test Case | Input | Expected Output |
---|---|---|
1 | ["2023-10-05", 5] | "2023-10-10" |
2 | ["2023-12-31", 1] | "2024-01-01" |
3 | ["2023-01-01", -1] | "2022-12-31" |
4 | ["2020-02-28", 1] | "2020-02-29" |
Leave a Comment
Please login to leave a comment.