function daysBetweenDates(date1: string, date2: string): number {
let msA = Date.parse(date1);
let msB = Date.parse(date2);
let DAY: number = 1000 * 60 * 60 * 24;
let diff = Math.abs(Math.round((msA - msB) / DAY));
return diff;
};
sol2 70
function daysBetweenDates(date1: string, date2: string): number {
if (typeof date1 == 'undefined' || typeof date2 == 'undefined')
return 0;
if (date1.length <= 0 || date2.length <= 0)
return 0;
const d1 = new Date(date1).getTime();
const d2 = new Date(date2).getTime();
let diff: number = 0;
if (d1 > d2) {
diff = d1 - d2;
} else {
diff = d2 - d1;
}
console.log("Total number of days between dates <br>"
+ d1 + "<br> and <br>"
+ d2 + " is: <br> "
+ diff);
return diff / (1000 * 3600 * 24);
};
sol3 80
function daysBetweenDates(date1: string, date2: string): number {
let dateInArray1: string = date1.split('-').join(' ');
let dateInArray2: string = date2.split('-').join(' ');
let utcTimeDayTakes: number = (1000 * 60 * 60 * 24);
return Math.abs(Date.parse(dateInArray1) - Date.parse(dateInArray2)) / utcTimeDayTakes;
};
mine 112
function daysBetweenDates(date1: string, date2: string): number {
let date11: Date = new Date(date1);
let date22: Date = new Date(date2);
let abs: number = Math.abs(date22.getTime() - date11.getTime());
let differ = Math.ceil(abs/(1000 * 3600 * 24));
return differ;
};