'Resolve time' from Seconds to hours/seconds (script help)

Andrew_TND
Mega Sage
Mega Sage

Because the community was so helpful with my last enquiry I have another question.

We have a resolve time which was configured in seconds. I need this in hours and minutes, I've looked on the community boards but still at a loss. 

This is made up of the hours between the incident opening and closing can someone help me with the script what I need to change to make hours and minutes?

var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};


var hours=function(x,y){return diff(x,y)/(60*60*1000);};


hours(current.opened_at, current.resolved_at);

1 ACCEPTED SOLUTION

radoslav
Tera Expert

Hi Andrew, 

 

you can try using this function as onLoad client script:

 

function getTime(seconds) {
   var myDate = new Date(0,0,0,0,0,x);
   var hours = '0' + myDate.getHours();
   var minutes = '0' + myDate.getMinutes();
   return hours.slice(-2) + ':' + minutes.slice(-2);
}

View solution in original post

2 REPLIES 2

radoslav
Tera Expert

Hi Andrew, 

 

you can try using this function as onLoad client script:

 

function getTime(seconds) {
   var myDate = new Date(0,0,0,0,0,x);
   var hours = '0' + myDate.getHours();
   var minutes = '0' + myDate.getMinutes();
   return hours.slice(-2) + ':' + minutes.slice(-2);
}

Shane J
Tera Guru

Create two new fields, one to hold 'minutes', one to hold 'hours'.

Take your value from 'seconds' and apply the appropriate math via Business Rule script to populate the other fields.

 

Unless I misread what your end goal is.