Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Created April 10, 2020 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/a11aff8c6ad8af8ee38dbeb250f17c64 to your computer and use it in GitHub Desktop.
Save mhkeller/a11aff8c6ad8af8ee38dbeb250f17c64 to your computer and use it in GitHub Desktop.
Generate a range of dates
// 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