← All Exercises
Date Difference Calculator
advancedjavascript
Background
Date arithmetic is essential in scheduling systems, age calculation, and time-based analytics dashboards.
Problem
Write a function that takes two date strings and a unit, returning the difference between the dates in the specified unit.
Input
Two ISO date strings and a unit string (days, hours, or minutes).
Output
A number representing the difference in the specified unit.
Sample tests
Sample 1
Input: "2025-01-01", "2025-01-10", "days"
Expected: 9
Your solution
Learning objective
Learn JavaScript Date manipulation, millisecond-based arithmetic, and unit conversion.