Get the number of Sundays of a month using moment.js

I need the total day sunday's

and saturday's

month. using the library moment.js

. Can someone help me. Thanks to

+3


source to share


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







All Articles