Calculate Business Day Difference between two dates?

snow_04
Giga Contributor

Hi,

How can we calculate business days between two dates i.e. one date value selected in Start Date Field and the other date would be the current Date(Today Date). I have tried the below code but it does not gives me the correct business days value:

gs.info(gs.now());
var date1 = '10/06/2020';
var dc = new DurationCalculator();
dc.setSchedule('Sys Id of the Schedule');
var dur = dc.calcScheduleDuration(date1,gs.now())/3600;
gs.info('Duration is' + dur);
1 ACCEPTED SOLUTION

Add date in correct format

var date1 = '2020-06-10';
var end = new GlideDateTime(date1);

 

And try again ...

 

 

Mark my ANSWER as CORRECT and HELPFUL if it helps...

 

Refrence:

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_GlideDateTimeAPI#r_G...

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please refer below links and they will help you:

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

https://community.servicenow.com/community?id=community_question&sys_id=2cc62f8cdb1bdb00200f0b55ca96...

https://community.servicenow.com/community?id=community_question&sys_id=43679f2fdba8e7845129a851ca96...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Santosh_Ksagar
Mega Sage
Mega Sage

Hi,

var gdt1 = GlideDateTime('2015-07-24 18:58:00');
var gdt2 = GlideDateTime('2015-07-24 19:01:00');
var duration1 = gs.dateDiff(gdt1, gdt2, false);

Thanks
Santosh

Swapnil Soni1
Giga Guru

Hi,

Please try this

 

find_real_file.png

 

find_real_file.png

 

Please mark correct or helpful if this helps you.

Thanks

Swapnil