How do I get a time breakdown for 30 minute increments?

Dan_Kane
ServiceNow Employee
ServiceNow Employee

What is the best way to do a breakdown based on 30 minute intervals? I know we can make an "Hour of day" bucket group to do things like identify the hour of day that an incident was opened. We have a need to get the half-hour increments of when records are created. Is this possible in a bucket group, or is there a better way to accomplish?

1 ACCEPTED SOLUTION

Adam Stout
ServiceNow Employee
ServiceNow Employee

I would create 48 buckets numbered 1-48 with names for each 30-minute block.   Then a script like this should be able to translate the created time to the bucket:



var get30MinuteBucket = function (time)


{


      var mSecs = time.getTime().getNumericValue();


      var min = mSecs / (1000 * 60);


      return Math.floor(min / 30);


};


get30MinuteBucket(current.sys_created_on);



Here is some code to test this:



// test code


var startTime = new GlideDateTime('2018-01-23 15:34');


var endTime = new GlideDateTime('2018-01-24 15:34');


while(startTime.compareTo(endTime) < 0)


{


      gs.addInfoMessage(startTime + ' - ' + get30MinuteBucket(startTime));


      startTime.addSeconds(60 * 43); // 43 minutes


}


View solution in original post

1 REPLY 1

Adam Stout
ServiceNow Employee
ServiceNow Employee

I would create 48 buckets numbered 1-48 with names for each 30-minute block.   Then a script like this should be able to translate the created time to the bucket:



var get30MinuteBucket = function (time)


{


      var mSecs = time.getTime().getNumericValue();


      var min = mSecs / (1000 * 60);


      return Math.floor(min / 30);


};


get30MinuteBucket(current.sys_created_on);



Here is some code to test this:



// test code


var startTime = new GlideDateTime('2018-01-23 15:34');


var endTime = new GlideDateTime('2018-01-24 15:34');


while(startTime.compareTo(endTime) < 0)


{


      gs.addInfoMessage(startTime + ' - ' + get30MinuteBucket(startTime));


      startTime.addSeconds(60 * 43); // 43 minutes


}