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

Convert HH:MM to decimal

Engaged ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

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

484

Translate

Translate

Report

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 ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

Define the function HHMM2Min.

Votes

Translate

Translate

Report

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
Engaged ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

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!.

 

Votes

Translate

Translate

Report

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 ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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