Looking for an arcade expression to take the death date and birth date and calculate the age. Here is what I am using but it appears it is using all of the dates rather than just the years.
Solved! Go to Solution.
You can use the Floor function to round the age to integer years.
var startDate = Date($feature.birthdate);
var endDate = Date($feature.deathdate);
var age = Floor(DateDiff(endDate, startDate, 'years'));
return age;
What do you mean, "all of the dates"? I don't see anything wrong with your expression. Do you just want the result rounded down? Try Floor(age) for that.
Actually, could you give an example of what is stored in the birtdate / deathdate fields? If they are true Date types, you don't need to wrap them in the Date() function. It's possible that the way these fields are being converted to dates is causing the issue.
You can use the Floor function to round the age to integer years.
var startDate = Date($feature.birthdate);
var endDate = Date($feature.deathdate);
var age = Floor(DateDiff(endDate, startDate, 'years'));
return age;
This appears to have worked! Thanks