2 Replies Latest reply on Nov 14, 2012 7:02 AM by jagan18

    Calculating age based on DOB


      Need to calculate a user age base on DOB field using AcroForms Javascript?

        • 1. Re: Calculating age based on DOB
          gkaiseril MVP & Adobe Community Professional

          From today some other date?


          And what do you want returned? Years only, years and months, years months and days, days, or other time value?


          Assuming you are using Acrobat and not LiveCycle Designer:


          // get dob string value of the DOB field

          var sDob = this.getField("DOB").value;

          // convert to date object

          var oDob = util.scand("dd-mmm-yyyy", sDob);

          // convert to milliseconds since Epoch date

          var nDob = oDob.getTime();

          // todays date in milliseconds since Epoch date

          var nToday =  (new Date()).getTime();

          // compute difference including end date

          var nDiff = nToday - (nDob + (1000 * 60 * 60 * 24)) ;

          // compute output in whole years

          event.value = Math.floor(nDiff / (1000 * 60 * 60 * 24 * 365.2425))

          • 2. Re: Calculating age based on DOB
            jagan18 Level 1

            Thanks, I was looking for it in years only.  I have a form in adobe acrobat with a DOB text box "mm/dd/yyyy" format.  Then I have a second text field that is the "age"  field, in which I need the user age to populate.  I was thinking on using the "on blur" action to fire the code and calculation javascript.  I know I can use the calculation custom script but was unsure how it fired the code.  Thanks for your respone and help.