The following example shows you how to add a new column in your view that will display the time elapsed between the launch of a new request and the current time OR the launch of a new request and its closure time (if the request is closed).
-
Choose Edit Columns > New Column.
-
Name the column “Time Elapsed”.
-
Choose Mode > JavaScript.
-
Replace the default code with the following:
function renderer(index, row, records){
var diff; //Time spent in milliseconds
var dateCreated; // Date of creation of the request
var dateClosed; // Date of closure of the request
dateCreated = Date.parse(row['created']);
if(row['closed'] !== undefined && row['closed']!=='')
{
dateClosed = Date.parse(row['closed']);
diff = Number(dateClosed - dateCreated);
}
else
{
diff = Number(Date.now() - dateCreated);
}
//We divide by 3600000 to get the time elapsed in hours
return ( (diff/3600000).toFixed(2) + " hours”);
}