Skip navigation
erinb1211
Currently Being Moderated

How do I calculate age based on user inputed birthdate?

Mar 19, 2012 3:37 PM

Tags: #javascript #forms #calculation #scripting #livecycle_es2 #adobe_livecycle #livecycle_designer

Hi there -

 

I'm working on a form where the user will enter both their date of birth and their start date for employment. I need to create two fields that will calculate their full years of age based on their date of birth, and their full number of years of service, based on their start date.

 

Does anyone have a good script that will make these calculations? I normally use FormCalc, but am open to Java if there's an easier solution.

 

Thanks,

Erin

 
Replies
  • Currently Being Moderated
    Mar 19, 2012 4:46 PM   in reply to erinb1211

    If you are using date fields, then on the calculate of the text fields, you can put something like

     

    if ( not DateTimeField1.isNull ) then
        var dateofBirth = Date2Num( DateTimeField1, "YYYY-MM-DD" )
        var currentDate = Date()
     
        var years = ( currentDate - dateofBirth ) / 365
        $ = Floor( years )
    else
        $ = ""
    endif
    

     

    will calc the age, while something similar for startdate

     

    if ( not DateTimeField2.isNull ) then
        var startDate = Date2Num( DateTimeField2, "YYYY-MM-DD" )
        var currentDate = Date()
     
        var years = ( currentDate - startDate ) / 365
        $ = Floor( years )
    else
        $ = ""
    endif
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2012 7:34 AM   in reply to erinb1211

    You could use Round function instead of Floor in the script, so something like

     

    $ = Round( years, 1 )

     

    using 1 decimal place

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points