Created
June 26, 2023 09:30
-
-
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.
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
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