Get the number of Sundays of a month using moment.js
1 answer
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
must be any date in the month that you want to parse.
fiddle works
NOTE: Sunday is 0 and Saturday 6
+2
source to share