javascript date range code example
Example 1: javascript date range
Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}
function getDates(startDate, stopDate) {
var dateArray = new Array();
var currentDate = startDate;
while (currentDate <= stopDate) {
dateArray.push(new Date (currentDate));
currentDate = currentDate.addDays(1);
}
return dateArray;
}
Example 2: javascript date range
Array(to - from + 1)
.fill('') // .fill() is not IE compliant
.map((_, i) => from + i));
// (2000, 2003) => [2000,2001,2002,2003]