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

Convert HH:MM to decimal

Engaged ,
Dec 14, 2021 Dec 14, 2021

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

Define the function HHMM2Min.

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

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

 

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

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

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