The CreatorCon Call for Content is officially open! Get started here.

Calculate Duration

coolsaurabh
Tera Contributor

Hi

I have two Date and Time type field Actual Start Date and Actual End Date and I have another field duration type field name as Duration.

I have to capture duration in this field. How can I do that ?

Thanks,

Sourabh

1 ACCEPTED SOLUTION

Paramahanns
Tera Expert

Hi sourabh,



Please create fields as below.



Actual Start Date


field name: startdate


Type: Date/time



Actual End Date


field name: enddate


Type: Date/time



Duration Type


field name: duration


Type: Duration



Create a business rule with the below code on which ever needed. Like on update or insert.



getTimeDiff();  


    function getTimeDiff(){  
  var startDate = current.u_startdate.getGlideObject();  
  var endDate = current.u_enddate.getGlideObject();  
 
  current.u_duration = gs.dateDiff(startDate.getDisplayValueInternal(),endDate.getDisplayValueInternal(),false);



find_real_file.png



Kindly mark as correct if this helps you.



Regards


Param


View solution in original post

3 REPLIES 3

shloke04
Kilo Patron

Hi,



You can refer the below links for implementing your solution:



Business Duration Calculation


Calculate Duration Given a Schedule - ServiceNow Wiki


Setting the Duration Field Value - ServiceNow Wiki



Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I wrote a post about using duration with a schedule here if you wanna take a look: How to close ticket after 3 business days



//Göran


Paramahanns
Tera Expert

Hi sourabh,



Please create fields as below.



Actual Start Date


field name: startdate


Type: Date/time



Actual End Date


field name: enddate


Type: Date/time



Duration Type


field name: duration


Type: Duration



Create a business rule with the below code on which ever needed. Like on update or insert.



getTimeDiff();  


    function getTimeDiff(){  
  var startDate = current.u_startdate.getGlideObject();  
  var endDate = current.u_enddate.getGlideObject();  
 
  current.u_duration = gs.dateDiff(startDate.getDisplayValueInternal(),endDate.getDisplayValueInternal(),false);



find_real_file.png



Kindly mark as correct if this helps you.



Regards


Param