Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ironars/a1c60e09efeb97099db24bccb49f1a34 to your computer and use it in GitHub Desktop.
Save ironars/a1c60e09efeb97099db24bccb49f1a34 to your computer and use it in GitHub Desktop.
Find the Saturdays and Sundays between 2 dates
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