Home » Jquery » jquery – How to get the number of days with dates of a given week number by using JavaScript

jquery – How to get the number of days with dates of a given week number by using JavaScript

Posted by: admin February 22, 2020 Leave a comment

Questions:

I want to show them in a loop
Having an understanding of JavaScript & jQuery.

I have done to get the week number in a loop by using this code, for now, I want to get all days with dates of the given week number

function printWeekNumber() {
    var dateFrom =
        document.getElementById("txtFrom").value;
    var dateF = new Date(dateFrom);
    var resultFrom = dateF.getWeekNumber();
    Date.prototype.getWeekNumber = function () {

        var oneJan =
            new Date(this.getFullYear(), 0, 1);

        // calculating number of days  
        //in given year before given date 

        var numberOfDays =
            Math.floor((this - oneJan) / (24 * 60 * 60 * 1000));

        // adding 1 since this.getDay() 
        //returns value starting from 0 

        return Math.ceil((this.getDay() + 1 + numberOfDays) / 7);

    }

    function printWeekNumber() {
        var dateFrom =
            document.getElementById("txtFrom").value;
        var dateF = new Date(dateFrom);
        var resultFrom = dateF.getWeekNumber();

        var dateTo =
            document.getElementById("txtTo").value;
        var dateT = new Date(dateTo);
        var resultTo = dateT.getWeekNumber();

        for (var i = resultFrom; i <= resultTo; i++) {
            alert(i);
        }

    }
}

Please help me I am stuck in this step.

How to&Answer: