Show all weeknumbers with their working days (with js or php)

I’m looking for a script where i can show all the working days (monday till friday) per weeknumber for a whole year.

week 1
02/01
03/01
04/01
05/01
06/01

week 2
09/01
10/01
etc…etc…for rest of the year.

Because i have no clue how to do this i’m also not 100% if i want to do this with javascript or php, both are fine for me.

I’m sure there is some place where this is explained, not sure what to search for though? Is there someone who can give me a push (or punch) in the right direction (for a beginner)?

I’m looking for a script where i can show all the working days (monday till friday) per weeknumber for a whole year.

week 1
02/01
03/01
04/01
05/01
06/01

week 2
09/01
10/01
etc…etc…for rest of the year.
Because i have no clue how to do this i’m also not 100% if i want to do this with javascript or php.

I’m sure there is some place where this is explained, not sure what to search for though? Is there someone who can give me a push (or punch) in the right direction (for a beginner)?

edit
So i got it working now. Not sure (as always) if this is the way to go but happy i got it now :slight_smile: Any thoughts?

function getDateOfISOWeek(w, y) {
    var simple = new Date(y, 0, 1 + (w - 1) * 7);
    var dow = simple.getDay();
    var ISOweekStart = simple;
    if (dow <= 4)
        ISOweekStart.setDate(simple.getDate() - simple.getDay() + 1);
    else
        ISOweekStart.setDate(simple.getDate() + 8 - simple.getDay());

    var firstDay = moment(ISOweekStart).format("YYYY-MM-DD");

    return firstDay;
}


for (i = 1; i < 53; i++) { 

    var workWeek = new Array();
    var firstDay = getDateOfISOWeek(i, 2017);

    for (x = 0; x < 5; x++) { 
    	var addingDays = moment(firstDay).add(x, 'd').format("YYYY-MM-DD");
    	workWeek.push(addingDays);

    	$('.test').append('week' + i + ' - day: ' + workWeek[x] + '<br>');
    }
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.