JSFiddle - React, Tailwind, and code Playground

by ryanbrill

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.6/dayjs.min.js"></script>

JavaScript

let months = [];
months.push(dayjs().subtract(1, 'month').startOf('month').format("YYYY-MM-DD"));
months.push(dayjs().startOf('month').format("YYYY-MM-DD"));

console.log(months);

let currentMonth = dayjs().get('month');
let weeks = [];
let week = dayjs().startOf('month').endOf('week');
while (week.get('month') <= currentMonth) {
  weeks.push(week.format('YYYY-MM-DD'))
	week = week.add(1, 'week');
}
if (dayjs(weeks[weeks.length - 1]).date() != dayjs().endOf('month').date()) {
	weeks.push(dayjs().endOf('month').format('YYYY-MM-DD'))
}
console.log(weeks)