Select to view content in your preferred language

Use arcade in AGOL forms for determining Age

676
4
Jump to solution
11-28-2023 09:10 AM
Laura
by MVP Regular Contributor
MVP Regular Contributor

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. 

 

Laura_0-1701191443263.png

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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;

 

View solution in original post

0 Kudos
4 Replies
jcarlson
MVP Esteemed Contributor

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.

- Josh Carlson
Kendall County GIS
0 Kudos
jcarlson
MVP Esteemed Contributor

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.

- Josh Carlson
Kendall County GIS
0 Kudos
KenBuja
MVP Esteemed Contributor

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;

 

0 Kudos
Laura
by MVP Regular Contributor
MVP Regular Contributor

This appears to have worked! Thanks 

0 Kudos