Issue with calculating difference between two dates

mattgr
Kilo Guru

HI,

 

I use BS rule to calculate data between two variables:

 

calDateDiff();  
 
  function calDateDiff(){  
  var startDate = current.variables.gdpr_received_date;  
  var endDate = current.variables.gdpr_actualcomp_date;  
current.business_duration = gs.calDateDiff(startDate,endDate,false);
  }

 

The first date is:

 

mattgr_0-1669917554836.png

The second one is:

mattgr_1-1669917598417.png

Why on ear SNow calculate this Business duration as:

mattgr_2-1669917644892.png

Any idea?

 

 

1 ACCEPTED SOLUTION

Sam Scott1
Tera Expert

gs.dateDiff will calculate the total duration between two dates, wheras calDateDiff will calculate the Business Duration as it relates to some defined calendar (hence cal in the function name). If you want the total difference, use gs.dateDiff. If you want a business duration, adjust the calendar in your instance until it matches your business operation schedule. Note, there are distinct fields on all task records for Duration (calendar_duration) and Business Duration (business_duration).

View solution in original post

3 REPLIES 3

Sam Scott1
Tera Expert

gs.dateDiff will calculate the total duration between two dates, wheras calDateDiff will calculate the Business Duration as it relates to some defined calendar (hence cal in the function name). If you want the total difference, use gs.dateDiff. If you want a business duration, adjust the calendar in your instance until it matches your business operation schedule. Note, there are distinct fields on all task records for Duration (calendar_duration) and Business Duration (business_duration).

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Below thread has solution.

https://www.servicenow.com/community/developer-forum/calculate-the-of-months-between-two-date-fields...

Please hit like and mark my response as correct if that helps
Regards,
Musab

Saurav11
Kilo Patron
Kilo Patron

Hello @mattgr 

 

What type of field is Business duration?