Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Mar 13, 2025 Mar 13, 2025

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

TOPICS
Create PDFs , JavaScript , PDF , PDF forms
130
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Mar 13, 2025 Mar 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);}

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2025 Mar 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);}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 13, 2025 Mar 13, 2025
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines