Counting weekdays in a period | Community
Skip to main content
February 15, 2023

Counting weekdays in a period

  • February 15, 2023
  • 1 reply
  • 1073 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Mayank_Gandhi
Adobe Employee
Adobe Employee
February 17, 2023

@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;
}
UKE87Author
February 17, 2023

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

Mayank_Gandhi
Adobe Employee
Adobe Employee
February 20, 2023

@uke87 I dont see the form.

here is the reference doc:

https://helpx.adobe.com/pdf/aem-forms/6-2/scripting-basics.pdf