6 Replies Latest reply on Aug 17, 2008 7:24 AM by gkaiseril

    Date Calculations

      Looking to subtract Date1 from Date2 and have the result be a number (either + or -).


        • 1. Re: Date Calculations
          (Aandi_Inston) Level 1
          Almost certainly, but what would you want the number to represent?

          For example, if it is "days"
          * Number of 24 hour periods, rounded up?
          * Number of 24 hour periods, rounded down?
          * Number of 24 hour periods, rounded to closest?
          * Number of calendar days falling in the interval?
          * Difference between dates, considered as days since a starting point,
          ignoring the time of day?

          Aandi Inston
          • 2. Re: Date Calculations
            Level 1
            Basically, I want to replication Excel's date calculation capability. That is, Start date - End date = x days. X days will appear in a column next to the date fields. So difference between dates ignoring time is what I think I need.

            Example: Start Date: 1-Jan-08 End Date: 15-Jan-08 Delta: 15



            P.S. Conditional formatting is next question...if +, will need red. If - then clear. Will work on that later tho!
            • 3. Re: Date Calculations
              gkaiseril MVP & Adobe Community Professional
              If you are using LiveCycle Designer you can use the "Date2Num()" function to get the number of days from LiveCycle Designer's Epoch date for each date and then subtract the number of days. You will also have to make sure you use the correct format string in the function.

              For AcroForms, the version 5 JavaScript Reference has an extended date and time calculation example.
              • 4. Re: Date Calculations
                Level 1

                Thanks for your help.

                You have a link to that 5.0 reference? I have found 7.0 and 6.0 Ref guides.

                Working in Acrobat 5.0 here myself (for now).
                • 5. Re: Date Calculations
                  Level 1
                  Is this right?

                  Acrobat JavaScript Scripting Reference (Acrobat 7.0.5)
                  • 6. Re: Date Calculations
                    gkaiseril MVP & Adobe Community Professional
                    Here is the link, http://www.adobe.com/devnet/acrobat/javascript.html, to Acrobat JaavaScript Documentation, the material for version 5 is at the very bottom of the page.

                    // document level function get floor value of a number
                    function Floor(fValue) {
                    return Math.floor(fValue);
                    } // end Floor function

                    // document level function to compute the number of days from the Epoch date
                    function Date2Num(sDate, sFormat) {
                    var fSecond =1000;
                    var fMinute = 60 * fSecond;
                    var fHour = 60 * fMinute;
                    var fDay = 24 * fHour;

                    var oDate = util.scand(sFormat, sDate); // convert string date to date time object
                    var fDate = oDate.valueOf(); // convert to milliseconds from epoch date;
                    var fDate = fDate / fDay; // milliseconds convert to days
                    var fDate = Floor(fDate); // convert to lowest whole number
                    return fDate; // return number of days
                    } // end Date2Num function

                    // custom filed calculation to compute the difference in days between 2 dates
                    // compute difference in minutes and convert to days
                    var Start = this.getField("Start date").value; // start date value
                    var sFormat = "mm/dd/yyyy"; // start date format
                    var End = this.getField("End date").value;
                    var sFormat = "mm/dd/yyyy"; // end date value
                    var eFormat = sFormat; // end date format
                    event.value = Date2Num(End, eFormat) - Date2Num(Start, sFormat);