1 Reply Latest reply on Jun 20, 2016 12:11 PM by gkaiseril

    Calculate #Years & #Months from mm/dd/yyyy to current date

    buddycafe Level 1



      Is there a way to calculate #Years & #Months (to be displayed in two separate fields) from a single field such as 01/01/2015 - Present (where present is today's system date)?



      Hidden Field 1: The system's UI will auto-populate from date: 01/01/2015

      Hidden Field 2: The system's UI will auto-populate the database date (generally today's date) ie 6/20/2016


      Script needed:Visible field 1: Display the year: 1  (just the number and not verbiage)

      Visible field 2: Display months: 

      # of days not needed




        • 1. Re: Calculate #Years & #Months from mm/dd/yyyy to current date
          gkaiseril MVP & Adobe Community Professional

          Have you searched for age calculations. You basically need to convert your 2 date strings into JavaScript date objects. One can then extract the years and month values. With these four values one can calculate the number of years and months. Most of the code provided will use a function to perform the calculation but functions can only return 1 item.


          This code is custom coding and the name of the fields is part of the code.