2 Replies Latest reply on Apr 2, 2013 12:57 PM by JavaNovice

    DateTime Calculation

    JavaNovice

      Hello.  I have a form in Adobe Acrobat X that has 2 date/time fields.  The script below is being used to calculate the difference in hours between the two fields.  Is there a way to get the result to show the minutes as time?  For example, if the difference is 8hrs and 15min the result shows 8.25 instead of 8:15.  Is there any way to have it return as 8:15?  Thank you for any help!  Here is the script currently being used:

       

      function Date2Num.jpg

        • 1. Re: DateTime Calculation
          gkaiseril MVP & Adobe Community Professional

          Duplicate post http://forums.adobe.com/message/5199749#5199749

           

          A nice feature of Acrobat forms is that the displayed format does not need to match the field value. So you can created a custom format script to convert the hours to HH:MM. This feature will allow one to accumulate all the elapsed times for a subtotal, total or grand total in hours but display the intervals various total in hours and minutes.

           

          Since this formatting could be repeated several times using a document level script for the conversion will cut down on the amount of code that needs to be entered and debugged.

           

          // document level script to convert Hours to HH;MM format

          function Num2Time(nHours) {

          if(nHours == 0) return ""; // 0 hours is a null srting

          else return util.printf("%,201.0f:%,102.0f", Math.floor(nHours), (nHours * 60) % 60);

          } // end Num2Time

          // end document level script

           

          // custom format script

          event.value = Num2Time(event.value);

          // end custom format script.

          • 2. Re: DateTime Calculation
            JavaNovice Level 1

            You are so awesome!

             

            I apologize for the double post...I realized too late that I originally put my question in the wrong forum.

             

            Thank you so much!