Expand my Community achievements bar.

Counting weekdays in a period

Avatar

Level 1

Hi experts,

 

I am not getting anywhere here.

 

The goal is to put out the number of individual weekdays days between two date fields.
In my form I could already generated a code, that put out the total number of working days in the entered period of datefield1 and datefield2.

 

How exactly can I realize that at the end is displayed for example:

 

Number of Mondays: 2
Number of Tuesdays: 2
Number of Wednesdays: 1

 

Here is my file:

https://www.acronaut.de/download/file.php?id=9980

4 Replies

Avatar

Employee Advisor

@UKE87 

 

try this

 

var startDate = new Date('15/03/2022');
var endDate = new Date('25/03/2022');
var numOfDates = getBusinessDatesCount(startDate,endDate);

function getBusinessDatesCount(startDate, endDate) {
    let count = 0;
    const curDate = new Date(startDate.getTime());
    while (curDate <= endDate) {
        const dayOfWeek = curDate.getDay();
        if(dayOfWeek !== 0 && dayOfWeek !== 6) count++;
        curDate.setDate(curDate.getDate() + 1);
    }
    app.alert(count);
    return count;
}

Avatar

Level 1

Could you help me again and tell me where I should use that code in my following form?

 

The goal is to get a value of each working day in the entered period.

 

Here is my form:

https://www.acronaut.de/download/file.php?id=10008

Avatar

Level 1

@Mayank_Gandhi 

 

Here is the link to my form: https://www.acronaut.de/download/file.php?id=10008

 

It would be great, If you could help me with the code in my form.