Created
May 4, 2016 16:46
-
-
Save xphong/2fdffe2b1142035286f345f5310b1ce2 to your computer and use it in GitHub Desktop.
Get number of business days in a selected month with Moment.js
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
// Usage: getNumberOfBusinessDaysInMonth(moment(), moment().daysInMonth()); | |
function getNumberOfBusinessDaysInMonth(date, days) { | |
var date = moment(date).startOf('month'); | |
var numberOfBusinessDays = 0; | |
while (days > 0) { | |
date = date.add(1, 'days'); | |
if (date.isoWeekday() !== 7 && date.isoWeekday() !== 1) { | |
numberOfBusinessDays += 1; | |
} | |
days -= 1; | |
} | |
return numberOfBusinessDays; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment