Created
April 10, 2020 03:09
-
-
Save mhkeller/a11aff8c6ad8af8ee38dbeb250f17c64 to your computer and use it in GitHub Desktop.
Generate a range of dates
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
// Adapted from here: https://stackoverflow.com/questions/4413590/javascript-get-array-of-dates-between-2-dates | |
module.exports = function genDateRange(start, end, format) { | |
let arr; | |
let dt; | |
for (arr = [], dt = new Date(start); dt <= end; dt.setDate(dt.getDate() + 1)) { | |
arr.push(new Date(dt)); | |
} | |
if (format === 'strings') { | |
return arr.map(v => v.toISOString().slice(0, 10)); | |
} | |
return arr; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment