Substracting two date fields to calculate age.

945
6
02-06-2020 06:26 AM
AbiDhakal
Occasional Contributor

Hello GIS friends,

Hope you all are well.

I have a question. I'm trying to find an arcade expression or sql expression to substract Created_Date field from Current_Date field to get the Age. Is this something that is possible? I will really appreciate your input in helping me with the expression.

Thank you,

Abi 

Tags (1)
0 Kudos
6 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Arcade Function Reference | ArcGIS for Developers 

There is a whole section on dates/times that will help

KayManuel
New Contributor

Hi @DanPatterson_Retired ,

Thanks for the link but it only talks about the date/time expressions. 

However, how do i get the calculated age to be displayed in the age field in field maps?

Should the data type of the age field be string or number or date even.

Advice from everyone is duly welcome.

0 Kudos
AbiDhakal
Occasional Contributor

Hey Dan,

Thank you for the direction. I tried this expression, but it did not run for me. I probably did not know how to insert the right fields in the expression. Here is the expression:

 var startDate = Date($feature.startDateField); var endDate = Date($feature.endDateField); var age = DateDiff(endDate, startDate, 'years'); return age;

I only have created_date field and an Age field. I would like the derivation to populate the Age field by substracting current_date which I do not have from created_date.

Thank you.

Abi

0 Kudos
LukeGilner1
New Contributor III

I know this is an older post, but I was successfully able to use your expression to calculate the age in my own data.  I seem to have better luck with Arcade when I enclose the field names in brackets and single quotes, but I also am using joined tables so that might be why.  For example Date($feature['startDateField']).

0 Kudos
BruceHarold
Esri Regular Contributor

if you are working in Pro you also have available arcpy.time.EsriTimeDelta()

MarkBockenhauer
Esri Regular Contributor

Abi,

You might find some information  in this blog article of use.  it shows how to use arcade to show information in a popup window based on hours of operation and current time.

mark