Skip to main content
Participant
March 13, 2025
Answered

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

  • March 13, 2025
  • 1 reply
  • 299 views

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

Correct answer Nesa Nurani

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);}

 

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
March 13, 2025

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);}

 

tim_2407Author
Participant
March 13, 2025

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