Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Created June 26, 2023 09:30
Show Gist options
  • Save bhaireshm/031d03bf03edac7e1e9407ac776be829 to your computer and use it in GitHub Desktop.
Save bhaireshm/031d03bf03edac7e1e9407ac776be829 to your computer and use it in GitHub Desktop.
Returns all the dates between the start date and end date, including both.
function getDatesInRange(startDate, endDate) {
if(!startDate || !endDate) return null;
startDate = new Date(startDate);
endDate = new Date(endDate);
const date = new Date(startDate.getTime());
const dates = [];
while (date <= endDate) {
dates.push(new Date(date));
date.setDate(date.getDate() + 1);
}
return dates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment