# Moment.js, How to Calculate Number of Given Weekday Between two dates

In this article, I will explain how to calculate total days from the given start and end dates and specific days of the weeks.

June 09, 2019

Moment.js is powerful library for your application that needs to deal with dates and times.

It comes with numerous functions that we can parse, validate, and manipulate dates and times.

For example, if given data is:

``````startDate: 06/03/2019 //Monday
endDate: 06/09/2019 //Sunday
// Sunday through Saturday
weekdayToCheck: [true, false, false, false, false, false, false] ``````

The function should return 1 since we have only one Sunday between those dates.

Here is my solution and note that my start and end dates are Moment objects:

``````const start = startDate.startOf('days');
const end = moment().startOf('days'); //today
//calculate only Tuesday
const dailyInfo = [false, false, true, false, false, false, false]
let totalDays = 0;

dailyInfo.forEach((info, index) => {
if (info === true) {
let current = start.clone();
if (current.isoWeekday() <= index) {
current = current.isoWeekday(index);
} else {
}
while (current.isSameOrBefore(end)) {
current.day(7 + index);
totalDays += 1;
}
}
});``````

Important part of calculation is this:

``````if (current.isoWeekday() <= index) {
current = current.isoWeekday(index);
} else {