I need the total number of sunday's
and saturday's
of a month. using moment.js
library. Can anyone help me. Thanks
Here is a solution using moment.js:
function getAmountOfWeekDaysInMonth(date, weekday){
date.date(1);
var dif = (7 + (weekday - date.weekday()))%7+1;
console.log("weekday: "+ weekday +", FirstOfMonth: "+ date.weekday() +", dif: "+dif);
return Math.floor((date.daysInMonth()-dif) / 7)+1;
}
The argument date
has to be any date in the month you want analyse.
working fiddle
NOTE: sunday is 0 and saturday 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With