Calculate Time differences

Vijaykumar K
Tera Contributor

Hi All, we have a request like ,

1.need to capture time difference between promoted on (date and time field) and current date and time untill restoration time(date and time) is empty and need to push this output to Time elapsed field(string field).

2.if Restoration is set the Time elapsed need to calculate between promoted time minus restoration time.

 

Could you pls help me with how to achieve this 

 

When to run before BR updated, major incident state is accepted.

 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Vijaykumar K 

here is the sample script for calculating the time difference. you can add this logic in your BR script

var plannedDatetime = new GlideDateTime(current.getValue('start_date'));
var actualDatetime = new GlideDateTime(current.getValue('work_start'));
var dur = new GlideDuration();
dur = GlideDateTime.subtract(plannedDatetime, actualDatetime); //the difference between 
var hour = dur.getByFormat('HH'); //get hour part
var mins = dur.getByFormat('mm'); //get mins
var day = dur.getDayPart();
Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Vijaykumar K 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Arun_S1
Tera Guru
Tera Guru

@Vijaykumar K This time difference between your promoted date and current date will be updated only when the major incident is modified. If your expectation is to have the updated time always,

 

for example today you update the major incident and the time difference will be exactly calculated and updated, but tomorrow when you look at the incident the difference will still be the same like yesterday and will not be automatically modified while using a BR.

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.

@Arun_S1  is it feasible to get current time always rather then update on Major incident update .?

 

Promoted to restoration is working as expected.