410 B
410 B
title, tags
| title | tags |
|---|---|
| daysBetween.md | date,begineer |
Returns the number of days between two Date objects.
- Subtract the two
Dateobjects and find the absolute value usingMath.abs() - Divide by the number of milliseconds in a day
const daysBetween = (date1, date2) =>
Math.abs(date1 - date2) / (1000 * 60 * 60 * 24)
daysBetween(new Date("11-1-2020"), new Date("11-3-2020")); // 2