Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141307

How can i filter a post only for the post which are posted in the current month and not in any other month in JavaScript?

$
0
0

I tried something like this and it takes 1 to 31 of every month. i need only for the current month.

Emptarray.unshift([addtodoValue.value, d.getDate(), `To do added on ${d.getDate()} ${months[d.getMonth()]} ${d.getFullYear()}`]);
    var date = new Date(), year = date.getFullYear(), month = date.getMonth(), date = date.getDate()
    var firstDay = new Date(year, month, 1);
    var lastDay = new Date(year, month + 1, 0);
    monthOutput = "";

    let monthFilt = Emptarray.filter(emp => {

        if (emp[1] <= lastDay.getDate() && emp[1] >= firstDay.getDate()) {
            monthOutput += `<div class="task-card" id="content-block"><div class="task-content"><h6 class="content">${emp[0]}</h6><small class="datestamp">${emp[2]}</small></div><div class="task-option"><img src="images/ellipsis.svg"></div></div>
    `;
            document.getElementById('month').innerHTML = monthOutput;
            console.log(emp[1])
        } else {
            return false;

        }
    })

Objective is to filter the post which are posted in the current month


Viewing all articles
Browse latest Browse all 141307

Trending Articles