[Chartjs]-How to show dynamic dates with month name of current month and previous month in momentjs?

2๐Ÿ‘

โœ…

//sample to display february days
var months = moment.monthsShort();

var datesofmonth = createAllDatesOfMonth(months[1], 2021)

console.log(datesofmonth);


function createAllDatesOfMonth(month, year) {
  let year_month = year + "-" + month;
  let nbdays = moment(year_month, "YYYY-MMM").daysInMonth();
  return Array.from(Array(nbdays).keys()).map((d) => month + " " + (d + 1));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.5.1/moment.min.js"></script>

Leave a comment