Follow

Calculating the Difference in Years Between Two Date Selectors

To calculate the difference in years between two dates you will need to use a computed label field.   A sample script is provided below:

NOTE:  You will need to replace the $date1$ and $date2$ fields with your own Date Selector field keys or the script will not work.

 

//ADD SCRIPT TO A COMPUTED LABEL FIELD


var date1 = dateFromString($date1$);
var date2 = dateFromString($date2$);
var dateDiff = new Date(date2 - date1);

var yearDiff = Math.abs(dateDiff.getUTCFullYear() - 1970);

return yearDiff;

function dateFromString(isoDateString) {
var parts = isoDateString.match(/\d+/g);
var isoTime = Date.UTC(parts[0], parts[1] - 1, parts[2], parts[3], parts[4], parts[5]);
var isoDate = new Date(isoTime);

return isoDate;
}

 

Have more questions? Submit a request

Comments

Powered by Zendesk