How do I add a new column in a view that represents the time elapsed in each request?

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).

  1. Choose Edit Columns > New Column.

  2. Name the column “Time Elapsed”.

  3. Choose Mode > JavaScript.

  4. 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);
                diff = Number( - dateCreated);

               //We divide by 3600000 to get the time elapsed in hours
               return ( (diff/3600000).toFixed(2) + " hours”);