Skip to main content
Participant
Mar 13, 2025 6:36 PM UTC
Answered

Does anyone have a script for Average Time of Day for 24hours?

I'm looking for a script that will do Average Time of Day for 24hours? for example "Start"=13:21 "End"=16:02 average time of day would be "Mean"=14:41.

 

Thanks

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
Mar 13, 2025 6:50 PM UTC

Let's say you have "Start" and "End" fields, use this in 3rd field where you want to show average time as custom calculation script:

var start = this.getField("Start").valueAsString.split(":");
var end = this.getField("End").valueAsString.split(":");

if (start.length !== 2 || end.length !== 2) {
 event.value = "";} 
else {
 var meanMinutes = Math.floor(((+start[0] * 60 + +start[1]) + (+end[0] * 60 + +end[1])) / 2);
 event.value = ("0" + Math.floor(meanMinutes / 60)).slice(-2) + ":" + ("0" + (meanMinutes % 60)).slice(-2);}

 

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
Mar 13, 2025 6:50 PM UTC

Let's say you have "Start" and "End" fields, use this in 3rd field where you want to show average time as custom calculation script:

var start = this.getField("Start").valueAsString.split(":");
var end = this.getField("End").valueAsString.split(":");

if (start.length !== 2 || end.length !== 2) {
 event.value = "";} 
else {
 var meanMinutes = Math.floor(((+start[0] * 60 + +start[1]) + (+end[0] * 60 + +end[1])) / 2);
 event.value = ("0" + Math.floor(meanMinutes / 60)).slice(-2) + ":" + ("0" + (meanMinutes % 60)).slice(-2);}

 

Translate
tim_2407Author
Participant
Mar 13, 2025 7:41 PM UTC

Thank you SO MUCH you're the BEST, works 100%.

Translate