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.
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