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

Calculating time

Community Beginner ,
May 23, 2022 May 23, 2022

I have a quote form I've created.  It works pretty great unless I need to calculate (or show) a 24 hr period which I can't seem to figure out how to do for the life of me.  If I put in the time of 6:00AM to 6:00 (as seen in the attached) it calculates to 0:00 hours instead of 24 hrs. Any solutions?

defaultl7clzr972w37_0-1653317269881.png

defaultl7clzr972w37_1-1653317383051.png

 

 

TOPICS
Create PDFs
1.2K
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
1 ACCEPTED SOLUTION
Community Expert ,
May 23, 2022 May 23, 2022

In that case you can just add an exception, like this:

if (hourDiff==0 && minDiff==0) hourDiff = 24;

View solution in original post

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 ,
May 23, 2022 May 23, 2022

Can the result be more than 24 hours? If so, you will have to specify the full date, or the script won't be able to know if 9:00 - 10:00 is one hour, or 25 hours, or 49 hours, etc.

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 Beginner ,
May 23, 2022 May 23, 2022

No.  The max time per line is 24 hrs.  

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 ,
May 23, 2022 May 23, 2022

In that case you can just add an exception, like this:

if (hourDiff==0 && minDiff==0) hourDiff = 24;

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 Beginner ,
May 23, 2022 May 23, 2022
I've tried adding the line in a couple different places and each time it is still producing a 0:00 outcome.  What am I doing wrong?  Sorry... I'm not a coder at all. lol.

var start = this.getField("FROMHRS1").valueAsString;
var finish = this.getField("TOHOURS1").valueAsString;
 
if (start=="" || finish=="") event.value = "";
if (hourDiff==0 && minDiff==0) hourDiff = 24;
else {
var startArr = start.split(":") ;
var finishArr = finish.split(":") ;
 
var hourDiff = finishArr[0] - startArr[0];
var minDiff = Math.floor(((finishArr[1] - startArr[1]) / 60)*100);
if (minDiff<0) {hourDiff--; minDiff += 100;}
if (hourDiff<0) hourDiff+=24;
if (minDiff.toString().length == 1) minDiff = '0' + minDiff;
event.value = hourDiff + ":" + minDiff;
    
}
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 Beginner ,
May 23, 2022 May 23, 2022

Never mind... got it working!  Thank you so much.

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
New Here ,
Sep 18, 2024 Sep 18, 2024
LATEST

You can resolve this issue by using a dedicated time calculator that accounts for 24-hour periods. It sounds like your form isn't recognizing the full day, but using a tool like this can help you calculate exact time differences, including 24-hour spans, and avoid the 0:00 result you're seeing. You might also need to adjust your form to ensure it handles such periods correctly.

 
 
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