Calculating age with two fields in ArcGIS Pro

1766
2
02-10-2020 12:43 PM
KathyAdelman
New Contributor II

How would you calculate age in ArcGIS Pro based on BornDate and DeathDate fields?  I am working on creating a feature class to map cemetery graves using the Collector app.  The two fields are both a date type.  I am trying to do this in ArcGIS Pro, which I am new at, and it looks like the formula to deduct the BornDate from DeathDate and divide by 365 is not working.  

Any suggestions?  

0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

Hi Kathy. Date fields are python datetime objects which can be handy.

Field 1 - Field 2     produces a TimeDelta object.

TimeDelta.total_seconds()  will produce the number of seconds of the timedelta object.

I believe the timedelta will take into account leap years so the result may be off several days from what you may expect.

Total_seconds = (TimeField1 - TimeField2).total_seconds()

SecInYear = (60*60*24*365.25)

Years = Total_seconds/SecInYear

This is very basic and prone to error. Hopefully someone can give a better answer

UriGilad_EsriAu
Esri Contributor

Hi Kathy, 

Insert a new 'Age' field  (numerical).

Calculate 'Age' field using Arcade, and insert the following:

var startDate = Date($feature.startDateField);

var endDate = Date($feature.endDateField);

var age = DateDiff(endDate, startDate, 'years');

return age;

for details see the DateDiff function in:

Date Functions | ArcGIS for Developers 

Hope this helps, 

Uri