How to find business days between 2 dates from form through client script ?

Snehal13
Kilo Sage

How to find business days between 2 dates from form through client script ? 

 

It must exclude the weekends. Note - This needs to be achieved from client script when start date and end dates are filled and immediately the duration field below it must populate the days

7 REPLIES 7

Hi @Snehal13 

 

As mentioned in before response, you can exclude weekends and holidays in the Schedule record you will create and than it will run only for working days.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Hi Anubhav,

 

I am using same your code. but it is not giving right answer.

out put

00:00:00

 

sujata sakhare
Tera Contributor

hi,

Try it.

function DateDiff() {
    var datefrom = Xrm.Page.getAttribute("new_datefrom").getValue();
    var dateto = Xrm.Page.getAttribute("new_dateto").getValue();

    var days = (dateto - datefrom) / (1000 * 60 * 60 * 24);
    Xrm.Page.getAttribute("new_daydiff").setValue(days);
}

 Thanks.