JavaScript version
diffDays.js
const diffDays = (date, otherDate) => Math.ceil(Math.abs(date - otherDate) / (1000 * 60 * 60 * 24));
TypeScript version
diffDays.ts
const diffDays = (date: Date, otherDate: Date): number =>
Math.ceil(Math.abs(date.valueOf() - otherDate.valueOf()) / (1000 * 60 * 60 * 24));
Examples
examples.js
diffDays(new Date('2014-12-19'), new Date('2020-01-01')); // 1839