Skip to main content
Inspiring
June 17, 2024
Answered

How to Calculate total of minutes using JavaScript

  • June 17, 2024
  • 1 reply
  • 3708 views

 

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. 

This topic has been closed for replies.
Correct answer 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 reply

PDF Automation Station
Community Expert
June 17, 2024

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

Inspiring
June 18, 2024

HH:MM.   And I don't know if it matters, but any hours entered would be during the day time.  So there should never be a situation where someone is putting in times around midnight. 

Inspiring
June 28, 2024

 

To clarify, divide the TOTAL minutes by 60.  Move /60 outside the last bracket.


Yay!! I'm sure there's code to do it, but I just formatted the cell to number with two decimal points.

 

Thank You!