Days Between Dates
Days Between Dates
Tags: Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes two date strings in the format "YYYY-MM-DD" and returns the number of days between them as an integer. This problem is designed to help you practice calculating the difference between dates
. The function should accept two parameters and return the number of days.
Constraints:
- Both inputs will be
strings
representing valid dates in the format "YYYY-MM-DD". - The function should
return
aninteger
representing the number of days between the two dates. - The order of the dates does not matter; the result should be the absolute difference.
- Use the
datetime
module.
Example:
- Input:
"2023-10-05", "2023-10-10"
- Output:
5
Test Case | Input | Expected Output |
---|---|---|
1 | ["2023-10-05", "2023-10-10"] | 5 |
2 | ["2023-12-31", "2024-01-01"] | 1 |
3 | ["2023-01-01", "2022-12-31"] | 1 |
4 | ["2020-02-28", "2020-03-01"] | 2 |
Leave a Comment
Please login to leave a comment.