JSFiddle - React, Tailwind, and code Playground
by rudiedirkx
JavaScript
Date.prototype.getYMD = function() {
return this.getFullYear() + '-' + (this.getMonth()+1) + '-' + this.getDate();
};
Date.prototype.getDaysDiff = function(d2) {
var d1 = this,
delta = d1 < d2 ? +1 : -1;
var days = 0;
while (d1.getYMD() != d2.getYMD()) {
days++;
d1.setDate(d1.getDate() + delta);
}
return delta * days;
}
d1 = new Date('October 16 2012');
d2 = new Date('November 7 2012');
console.log(d1.getDaysDiff(d2));