Necesito encontrar cuantas semanas hay en un mes. Por ejemplo, la fecha de inicio es (24-04-2021) y la fecha de finalización es (01-05-2021). El mes de abril tiene cinco semanas, pero solo obtenemos 4 semanas como salida. esto es lo que he intentado hasta ahora
function getWeekOfMonth(date) { const startWeekDayIndex = 1; // 1 MonthDay 0 Sundays const firstDate = new Date(date.getFullYear(), date.getMonth(), 1); const firstDay = firstDate.getDay(); let weekNumber = Math.ceil((date.getDate() + firstDay) / 7); if (startWeekDayIndex === 1) { if (date.getDay() === 0 && date.getDate() > 1) { weekNumber -= 1; } if (firstDate.getDate() === 1 && firstDay === 0 && date.getDate() > 1) { weekNumber += 1; } } return weekNumber; }