Count number of days excluding weekends, Holidays.

Miguel1
Tera Contributor

Hi Experts!
I made business rule that count the number of days between two dates and it works but I would like to know how to exclude weekends 

for example if te user put 24-04-2020 in 'comienzo' field and 28-04-2020 in 'Fin' field the script returns 4 days but there is a weekend between these dates, so, How can I exclude that weekend? and the script returns 2 days. Same example for holidays like July 5th.

If anyone knows how I could do this I would really appreciate it!

thanks so much!!

 

(function executeRule(current, previous /*null when async*/) {
var realCom = new GlideDate(); 
realCom.setDisplayValue(current.u_comienzo_real.getDisplayValue()); //Field comienzo

var realFin = new GlideDate();
realFin.setDisplayValue(current.u_fin_real.getDisplayValue()); //Field Fin 

var seconds = gs.dateDiff(realCom,realFin,true);
var value = Math.floor(seconds/86400);
var x = parseInt(value,10);
current.setValue("u_duracion_real_dias",x + " DĂ­as");


})(current, previous);

find_real_file.png

 

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

Check this:

https://community.servicenow.com/community?id=community_question&sys_id=9f3900f1db8f2b407d3e02d5ca96...

Basically you need to use schedule to calculate this date.

Thanks,
Ashutosh

View solution in original post

5 REPLIES 5

Hi rajneeshbaranwal!

I did something similar and it worked, only with some settings according to the script