- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 12:19 PM
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);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 12:50 PM
HI,
Check this:
Basically you need to use schedule to calculate this date.
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 12:50 PM
HI,
Check this:
Basically you need to use schedule to calculate this date.
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2020 12:02 PM
HI,
Any update on this.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2020 01:41 PM
Hi Ashutosh!
I based on the post and it worked, thank you very much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 02:40 PM
You need to create a schedule excluding holidays and then use GlideSchedule.duration function to calculate difference between two datetime field.
Something like below.
var schedule = new GlideSchedule('sys_id_of_your_schedule');
schedule.duration(gdt1,gdt2);
Note that the returned duration value will be in second.
Please mark correct/helpful, if my answer helped you.