0 Replies Latest reply on Dec 17, 2012 9:29 AM by erinb1211

    How to calculate age in years and months?


      Hello -


      I currently have a form that calculates a person's age in full years using the following script (FormCalc):


      if ( not Row1[1].DateTimeField1 <> Null ) then

          var DateTimeField1 = Date2Num( Row1[1].DateTimeField1, "YYYY-MM-DD" )

          var currentDate = Date()


          var years = ( currentDate - DateTimeField1 ) / 365

          $ = Floor ( years )


          $ = ""



      I need to change this formula to instead calculate the age in years and months. For instance, if the user inputs their date of birth as 01/15/1979, then the output field would read, 33.11, for 33 years, 11 months.


      I know that I can remove the floor function to get partial years, but that results in the partial year dividing by 10, not 12. I tried that with the above date and the result was 33.9...


      Does anyone know how to edit this script?