- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2022 05:25 AM
Hii Team,
There is two dates fields Start date and end Date, my requirement is :
I need difference between of these two dates , but only need to calculate business day
For Example : if i select start date 2 may 2022 and end date 15 may 2022, there date difference is 14 days, but i need answer 10 days as 4 days are weekend.
I wrote these script:
var dur = gs.dateDiff(current.start_date, current.end_date);
var dateDifference = new GlideDuration(dur);
var d = dateDifference.getDayPart();
gs.addInfoMessage(d);
By these script , my total 14 days is coming, but i am not able to understand , how i calculate only weekdays.
Need Help
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022 06:52 AM
Hi Aayushi,
You need to create one schedule in which you need to exclude the weekends and set the time of business days and use sys ID of schedule in below code.
var dc = new DurationCalculator();
dc.setSchedule('<sys ID of schedule>');
var diff = dc.calcScheduleDuration(current.start_date, current.end_date) ;
Please mark reply as Correct/Helpful, if applicable. Thanks!
Thanks and Regards,
Neeraj Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2022 05:30 AM
Hello,
When you say business day, if you want to exclude holidays as well.. then using schedule is a better option.
Please find below ref -
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022 06:43 AM
Hello
Did you get chance to look into solution provided by me. Please let me know if you need any help.
If my answer helped you in any way, please then mark it as Correct/helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022 06:52 AM
Hi Aayushi,
You need to create one schedule in which you need to exclude the weekends and set the time of business days and use sys ID of schedule in below code.
var dc = new DurationCalculator();
dc.setSchedule('<sys ID of schedule>');
var diff = dc.calcScheduleDuration(current.start_date, current.end_date) ;
Please mark reply as Correct/Helpful, if applicable. Thanks!
Thanks and Regards,
Neeraj Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2022 07:23 AM
Hi Aayushi,
Please mark reply as Correct/Helpful, if applicable. Thanks!
Thanks and Regards,
Neeraj Sharma