Hi,
This code example will pull the date from a field named “Birthday”, and write it to a field named “Age”. Please note that this will be a static value, and will not automatically tick up a notch next year without you editing the list item.
Put this in the Custom JS:
function calculateAge(){
var dfo, sDate, now, age;
dfo = spjs.dffs.getRegionalSettings().DateFormat;
sDate = spjs.dffs.strToDateObj("Birthday",dfo);
now = new Date();
age = now.getFullYear() - sDate.getFullYear();
if(now.getMonth() < sDate.getMonth()){
age -= 1;
}else if(now.getMonth() === sDate.getMonth()){
if(now.getDate() < sDate.getDate()){
age -= 1;
}
}
setFieldValue("Age",age);
}
Then call this function from a rule in DFFS by putting the function name in the “Run these functions / trigger these rules” field.
Let me know how it works out.
Alexander