4 Replies Latest reply on Aug 7, 2008 3:38 PM by gkaiseril

    Calculate number of days between two dates

    Level 1
      Hi All,

      I'm using Acrobat Professional 8 and new to this, in fact only created my first interactive form today.

      My field names are: [DateIn] and [DateOut] and results populated in [TotalDays]

      I would like to calculate how many dates are between the dates in these two fields.

      I actually would like to take it one step further if possible and add 1 day to the [TotalDays] field if [TimeOut] is 4hrs or more than [TimeIn].

      Thanks guys :)
        • 1. Re: Calculate number of days between two dates
          DimitriM Level 3
          Hi Greg,

          Here is an article that can help you with this-
          http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/date_time_part1/

          ( that is Part 1 of a series of 3 articles on working with dates and time in Acrobat- the others should be helpful too.)

          Hope this helps,

          Dimitri
          WindJack Solutions
          www.windjack.com
          www.pdfscripting.com
          • 2. Re: Calculate number of days between two dates
            Level 1
            Hi Dimitri,

            Wow, this stuff is full on !!!

            I've come up with the following, which doesn't work, i know it'll be something i'm doing wrong, can you take a look at it for me?

            ----- form1.#subform[0].TotalDays::calculate - (FormCalc, client) ----------------------------------

            var strStart = this.getField("DateIn").value;
            var strEnd = this.getField("DateOut").value;
            if(strStart.length & strEnd.length)
            var dateIn = util.scand("d/MM/YY",strStart);
            var dateOut = util.scand("d/MM/YY",strEnd);
            var diff = dateout.getTime() - datein.getTime();
            var oneDay = 24 * 60 * 60 * 1000;
            var days = Math.floor(diff/oneDay);
            event.value = days;
            else
            event.value = 0;
            • 3. Re: Calculate number of days between two dates
              Larry G. Schneider Adobe Community Professional & MVP
              You need at least two digits in your day format "DD/MM/YY".
              • 4. Re: Calculate number of days between two dates
                gkaiseril MVP & Adobe Community Professional
                For others looking for more information, download a copy the Acrobat Version 5 JavaScript Reference. There is a section of Scripting examples that provides a example of time calculations.

                I prefer to use 4 digit years because of the change in the millennium.

                If one is using LiveCycle Designer, there are additional functions in FormCalc and the JavaScript has many differences that one will need to make adjustment for.