Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Days Between Dates

Numbers, Dates & Timersmedium

Course · Section 12: Numbers, Dates, Intl and Timers · Lecture 189: Operations With Dates

Implement `daysBetween(a, b)` returning the whole number of days between two ISO date strings (`YYYY-MM-DD`).

Sample tests

Input: daysBetween("2024-01-01", "2024-01-10")
Output: 9
Input: daysBetween("2024-01-01", "2024-01-01")
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Daylight-saving shifts can affect local times; ISO dates parse as UTC which avoids that.
Approach & explanation (try first)

The millisecond difference divided by a day's milliseconds gives the day count.

Loading...
⌘/Ctrl + Enter

Run your code to see results.