Skip to content

Instantly share code, notes, and snippets.

@hieudang59
Created October 15, 2019 15:22
Show Gist options
  • Save hieudang59/2551b186f805a56d92540ef1ff8f4c63 to your computer and use it in GitHub Desktop.
Save hieudang59/2551b186f805a56d92540ef1ff8f4c63 to your computer and use it in GitHub Desktop.
Returns an array of dates between the two dates
// Returns an array of dates between the two dates
var getDates = function(startDate, endDate) {
var dates = [],
currentDate = startDate,
addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
};
while (currentDate <= endDate) {
dates.push(currentDate);
currentDate = addDays.call(currentDate, 1);
}
return dates;
};
var dates = getDates(new Date(2019,10,01), new Date(2019,12,31));
dates.forEach(function(date) {
console.log(date);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment