Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Calculating age to a specific date


Level 1

I have a file that calculates someones age to the current date.  In one field you type the date, and in the other the age appears.  I need it to calculate a persons age at October 1, 2010 instead of the current date.  I do not know how to attach the file so here is the xml code as it appears in LiveCycle

<?xml version="1.0" encoding="UTF-8"?>

<?xfa generator="AdobeLiveCycleDesignerES_V9." APIVersion="3.1.9277.0"?>

<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2010-07-18T20:08:58Z" uuid="76c87f42-7062-4fca-a1ed-205e34ae0e47">

<template xmlns="http://www.xfa.org/schema/xfa-template/2.6/">

   <?formServer defaultPDFRenderFormat acrobat8.1static?>

   <subform name="form1" layout="tb" locale="en_US" restoreState="auto">


         <pageArea name="Page1" id="Page1">

            <contentArea x="0.25in" y="0.25in" w="8in" h="10.5in"/>

            <medium stock="letter" short="8.5in" long="11in"/>

            <?templateDesigner expand 1?></pageArea>

         <?templateDesigner expand 1?></pageSet>

      <subform w="8in" h="10.5in">

         <field name="DOB" y="22.225mm" x="25.4mm" w="62mm" h="9mm">


               <textEdit multiLine="1">

                  <border presence="hidden">

                     <?templateDesigner StyleID aped0?></border>




            <font typeface="Myriad Pro"/>

            <margin topInset="1mm" bottomInset="1mm" leftInset="1mm" rightInset="1mm"/>

            <para vAlign="middle"/>

            <caption reserve="20.7516mm">

               <para vAlign="middle"/>


                  <text>Date of Birth:</text>




         <field name="Age" y="22.225mm" x="101.6mm" w="25.4mm" h="9mm">




                     <?templateDesigner StyleID aped3?>

                     <edge stroke="lowered"/>





            <font typeface="Myriad Pro"/>

            <margin topInset="1mm" bottomInset="1mm" leftInset="1mm" rightInset="1mm"/>

            <para vAlign="middle"/>

            <caption reserve="8.0666mm">

               <para vAlign="middle"/>





            <calculate override="warning">

               <script contentType="application/x-javascript">

var ageInYears = 0;

var birthDate = new Date();

if ( DOB.rawValue != null )


// Get current date, and convert user-entered date to a Date object.

var curDate = new Date();


// Set initial age, current year - birth year

ageInYears = curDate.getFullYear() - birthDate.getFullYear();

// If we haven't reached the birth month yet, not yet 1 year older...

if ( curDate.getMonth() &lt; birthDate.getMonth() )


// If this month is same as birth month but we haven't reached the

// birth date yet, not yet 1 year older...

if ( curDate.getMonth() == birthDate.getMonth() )

if ( curDate.getDate() &lt; birthDate.getDate() )


// Set age in result field.

this.rawValue = ageInYears;





         <?templateDesigner expand 1?></subform>



         <text name="version"></text>


      <?templateDesigner expand 1?></subform>

   <?templateDesigner DefaultLanguage FormCalc?>

   <?templateDesigner DefaultRunAt client?>

   <?templateDesigner Grid show:1, snap:1, units:0, color:ff8080, origin:(0,0), interval:(125000,125000)?>

   <?acrobat JavaScript strictScoping?>

   <?templateDesigner Zoom 89?>

   <?templateDesigner FormTargetVersion 26?>

   <?templateDesigner Rulers horizontal:1, vertical:1, guidelines:1, crosshairs:0?>

   <?templateDesigner SaveTaggedPDF 1?>

   <?templateDesigner SavePDFWithEmbeddedFonts 1?></template>

<config xmlns="http://www.xfa.org/schema/xci/2.6/">

   <agent name="designer">

      <!--  [0..n]  -->



         <!--  [0..n]  -->





      <!--  [0..n]  -->


         <!--  [0..n]  -->













<localeSet xmlns="http://www.xfa.org/schema/xfa-locale-set/2.6/">

   <locale name="en_US" desc="English (United States)">

      <calendarSymbols name="gregorian">















         <monthNames abbr="1">























         <dayNames abbr="1">



















         <datePattern name="full">EEEE, MMMM D, YYYY</datePattern>

         <datePattern name="long">MMMM D, YYYY</datePattern>

         <datePattern name="med">MMM D, YYYY</datePattern>

         <datePattern name="short">M/D/YY</datePattern>



         <timePattern name="full">h:MM:SS A Z</timePattern>

         <timePattern name="long">h:MM:SS A Z</timePattern>

         <timePattern name="med">h:MM:SS A</timePattern>

         <timePattern name="short">h:MM A</timePattern>




         <numberPattern name="numeric">z,zz9.zzz</numberPattern>

         <numberPattern name="currency">$z,zz9.99|($z,zz9.99)</numberPattern>

         <numberPattern name="percent">z,zz9%</numberPattern>



         <numberSymbol name="decimal">.</numberSymbol>

         <numberSymbol name="grouping">,</numberSymbol>

         <numberSymbol name="percent">%</numberSymbol>

         <numberSymbol name="minus">-</numberSymbol>

         <numberSymbol name="zero">0</numberSymbol>



         <currencySymbol name="symbol">$</currencySymbol>

         <currencySymbol name="isoname">USD</currencySymbol>

         <currencySymbol name="decimal">.</currencySymbol>



         <typeface name="Myriad Pro"/>

         <typeface name="Minion Pro"/>

         <typeface name="Courier Std"/>

         <typeface name="Adobe Pi Std"/>

         <typeface name="Adobe Hebrew"/>

         <typeface name="Adobe Arabic"/>

         <typeface name="Adobe Thai"/>

         <typeface name="Kozuka Gothic Pro-VI M"/>

         <typeface name="Kozuka Mincho Pro-VI R"/>

         <typeface name="Adobe Ming Std L"/>

         <typeface name="Adobe Song Std L"/>

         <typeface name="Adobe Myungjo Std M"/>




<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">

   <xfa:data xfa:dataNode="dataGroup"/>


<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.398682, 2009/08/10-13:00:47        ">

   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

      <rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/" rdf:about="">


         <xmp:CreatorTool>Adobe LiveCycle Designer ES 9.0</xmp:CreatorTool>


      <rdf:Description xmlns:pdf="http://ns.adobe.com/pdf/1.3/" rdf:about="">

         <pdf:Producer>Adobe LiveCycle Designer ES 9.0</pdf:Producer>


      <rdf:Description xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" rdf:about="">




      <rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">



      <rdf:Description xmlns:desc="http://ns.adobe.com/xfa/promoted-desc/" rdf:about="">

         <desc:version rdf:parseType="Resource">







<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">



4 Replies


Former Community Member

Take a look at the attached. I think I have it right although my FormCalc skills leave something to be desired.

// form1.page1.ageAsOfDate::calculate - (FormCalc, client)

if (HasValue(dob)) then

  if (HasValue(selectedDate)) then

    var selectedDate_ = Date2Num(selectedDate.formattedValue, "MM/DD/YYYY")

    var dob_ = Date2Num(dob.formattedValue, "MM/DD/YYYY")

    var diff = selectedDate_ - dob_

    $.rawValue = Floor(diff / 365.25)


    $.rawValue = null



  $.rawValue = null





Level 1

Hey, this works really great and I have a follow up question.  I set the date to calculate someones age as of October 1, 2010.  When they type in their birth date, that age pops up in the age box.  I want to use the age that pops up in that box to control some radio buttons later in my document.  For example, if they are under the age of sixteen, then certain buttons will be disabled.  The only way I can get this to work is to have the person click on there age after it is auto calculated.  That clicking activates the disabled command.  I want the command to initialize immediately after they type in there birthdate.  I only want the field where they can enter their birthdate on my form.  The rest will be invisible.  Is there a way to do that?  Thanks for your help.


Former Community Member

Added a button and the following on the button calculate event...

// form1.page1.btn::calculate - (JavaScript, client)

form1.page1.btn.access = "open";

var age = parseInt(form1.page1.ageAsOfDate.rawValue);

if (age < 16) {

  form1.page1.btn.access = "protected";




Former Community Member

Nearly there!  Many thanks for your simple little formula.  I got it working as follows:

if (HasValue(Page1.studentdetails.dob)) then
   if (HasValue(rdtestdate)) then
      var rdtestdate_ = Date2Num(rdtestdate.formattedValue, "DD/MM/YYYY")
      var dob_ = Date2Num(Page1.studentdetails.dob.formattedValue, "DD/MM/YYYY")
      var diff = rdtestdate_ - dob_
      $.rawValue = Floor(diff / 365.25)
   $.rawValue = null
$.rawValue = null

What I need is to report the results in terms of years and months rather than round to years only.  How can I get the result to be formatted as years and months?

Many thanks for your assistance!