Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Number of Days Between Two Dates

XPChallenge Points: 10
levelLevel: Easy

You are given two date strings representing two calendar days in the format "YYYY-MM-DD".
Your task is to determine how many days lie between these two dates.

The order of the two dates does not matter — the result should always be the absolute difference in days.

Example 1:

Input: date1 = "2021-03-01", date2 = "2021-03-10"

Output: 9

Explanation:

There are exactly 9 days from March 1st to March 10th.

Example 2:

Input: date1 = "2022-12-25", date2 = "2023-01-01"

Output: 7

Explanation:

Seven days separate these two dates.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result