Created
March 5, 2020 10:42
-
-
Save ironars/a1c60e09efeb97099db24bccb49f1a34 to your computer and use it in GitHub Desktop.
Find the Saturdays and Sundays between 2 dates
This file contains hidden or 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 getWeekends(start, end) { | |
var startDate = new Date(start); | |
var endDate = new Date(end); | |
var weekendDays = 0; | |
while (startDate <= endDate) { | |
var day = startDate.getDay() | |
if (day == 0 || day == 6) { | |
weekendDays++; | |
} | |
startDate.setDate(startDate.getDate() + 1) | |
} | |
console.log(weekendDays); | |
} | |
getWeekends('03/01/2020', '03/31/2020'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment