Skip to main content
Inspiring
June 17, 2024
해결됨

How to Calculate total of minutes using JavaScript

  • June 17, 2024
  • 1 답변
  • 3785 조회

 

Hello, I don't do javascript here and while I tried searching.....I am not sure if any of the results I landed on pertain to me. Here are the fields I have.

 

Start Time

End Time

Total Time (In minutes)

 

The start/end times are military time format.  Just need the Total Time filed calculated and displayed in minutes. 

이 주제는 답변이 닫혔습니다.
최고의 답변: PDF Automation Station

Assuming the values in Start Time and End Time follow this format:  15:31, enter this custom calculation script in the Total Time field:

 

var startHour=this.getField("Start Time").value.split(":")[0];
var startMin=this.getField("Start Time").value.split(":")[1];
var endHour=this.getField("End Time").value.split(":")[0];
var endMin=this.getField("End Time").value.split(":")[1];


event.value=Number(60*(endHour-startHour)) + Number(endMin-startMin);

1 답변

PDF Automation Station
Community Expert
Community Expert
June 17, 2024

Please post the exact format of Start Time and End Time.

PDF Automation Station
Community Expert
Community Expert
June 17, 2024

Assuming the values in Start Time and End Time follow this format:  15:31, enter this custom calculation script in the Total Time field:

 

var startHour=this.getField("Start Time").value.split(":")[0];
var startMin=this.getField("Start Time").value.split(":")[1];
var endHour=this.getField("End Time").value.split(":")[0];
var endMin=this.getField("End Time").value.split(":")[1];


event.value=Number(60*(endHour-startHour)) + Number(endMin-startMin);

try67
Community Expert
Community Expert
June 17, 2024

This also assumes the end time is on the same date as the start time. If the start time is 23:50 and the end time is 00:25, it won't work correctly.