• Convert HH:MM to decimal

# Convert HH:MM to decimal

Engaged ,
Dec 14, 2021 Dec 14, 2021

Copied

Hi,

Have the following script to add up various time values.....is there any way to have a decimal value (e.g. 1:30 becoming 1.5) instead of the "HH:MM" as calculated?

var aFields = new Array("BlockTimeLine1", "BlockTimeLine2", "BlockTimeLine3", "BlockTimeLine4", "BlockTimeLine5", "BlockTimeLine6", "BlockTimeLine7", "BlockTimeLine8");

var nSum = 0;

var sTime;

for(i = 0; i < aFields.length; i++) {
sTime = this.getField(aFields[i]).valueAsString;
if(sTime == "") sTime = "00:00";
nSum += HHMM2Min(sTime);
}

event.value = Min2HHMM(nSum);
function Min2HHMM(nMinutes) {
var s = util.printf("%,001.0f:%,202.0f", Math.floor(nMinutes / 60), nMinutes % 60);
return s;
}

TOPICS
PDF forms

Views

63

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
3 Replies 3
Dec 14, 2021 Dec 14, 2021

Copied

Define the function HHMM2Min.

Likes

Report

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

Copied

Ah, sorry Bernd - this is just a script I used somewhere before, and not being a JS expert by any means - I couldn't tell you as time calcs. have always been a mystery to me!.

Likes

Report

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

Copied

LATEST

You can find the functions HHMM2Min and Min2HHMM on the Web.

Likes

Report

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