1
votes

I am not sure if this is possible?

I need to get the code to read

Todays month ie Feb Todays date ie 17 End of month date ie 31 and then the other 11 months of the years in order on one line

Aug 1 - 31 | Sep | Oct | Nov | Dec | Jan | Feb | Mar | Apr | May | Jun | Jul

Any suggestions in the best way to do this please?

Many thanks

Tim

1
you might want to look into moment js or another library like that.user241244

1 Answers

3
votes

Try this.

const months= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var newMonths = "";
var d = new Date();

// Find current day, month and last day of month
var currentDay = d.getDate();
var lastDay = new Date(d.getFullYear(), d.getMonth() + 1, 0, 23, 59, 59).getDate();
var month = d.getMonth();

for (var i = month + 1; i <= 11; i++) {
    newMonths = newMonths +" | " + months[i];
}
for (var i = 0; i < month; i++) {
    newMonths = newMonths +" | " + months[i];
}

console.log(months[month] + " " + currentDay + " - " + lastDay + " " + newMonths);

Here is the updated jdfiddle https://jsfiddle.net/k04amscv/