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
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Thank you so much! That worked perfectly.
Views
Replies
Total Likes
Would it be possible to change the calculation for the Years of Employment to calculate years and months? For example, if the input is 2/26/2011, the output would be 1.1 (1 year, 1 month)?
Views
Replies
Total Likes
You could use Round function instead of Floor in the script, so something like
$ = Round( years, 1 )
using 1 decimal place
Views
Replies
Total Likes
Views
Likes
Replies