Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View harshadbankar's full-sized avatar

Harshad harshadbankar

View GitHub Profile
@markthiessen
markthiessen / getWeeksInMonth.js
Last active January 29, 2024 01:00
JavaScript - get weeks in a month as array of start and end days
//note: month is 0 based, just like Dates in js
function getWeeksInMonth(year, month) {
const weeks = [],
firstDate = new Date(year, month, 1),
lastDate = new Date(year, month + 1, 0),
numDays = lastDate.getDate();
let dayOfWeekCounter = firstDate.getDay();
for (let date = 1; date <= numDays; date++) {