Created
October 9, 2019 09:34
-
-
Save hieudang-agilityio/6b473b831b812dad831e3e32910779e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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