- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Date Arithmetic
JavaScript Dates
JavaScript Date Arithmetic
Dates can be compared and subtracted because they are numbers underneath.
Subtracting two dates gives the difference in milliseconds.
Dividing that number converts it to days, hours or minutes.
Example
Example
javascript
const start = new Date(Date.UTC(2026, 0, 1));
const end = new Date(Date.UTC(2026, 0, 15));
const days = (end - start) / (1000 * 60 * 60 * 24);
console.log(days);