Calculate the difference in years between two dates
Hi
I have 4 fields named year1, year2, year3, year4 respectively.
I want to calculate the difference in years with respect to the dates entered respectively in "HIRES1", "HIRES2", ASSUNCTION3, ASSUNCTION4.
In the calculation script of each field I have inserted this formula
var s1 = this.getField("HIRES1").value;date = util.scand("mm/dd/yyyy",s1);now = new Date();difference_in_years = (now.getFullYear()) - date. getFullYear();if (now.getMonth()<date.getMonth()) {difference_in_years--;} else if ((now.getMonth()==date.getMonth()) && (now.getDate()<date .getDate())) {difference_in_years--;}event.value = difference_in_years;
The formula works to calculate the years starting from the date inserted in "ASSUNCTION1", while for the other fields the console gives me this error message
TypeError: date is null
1:Console:Exec
undefined
Anyone who can help me solve this problem?
Thank you
