Select to view content in your preferred language

Expression-create new field with value difference from two different dates

463
2
09-18-2023 09:10 AM
Labels (2)
TomKukitz
New Contributor III

Hi I am looking to create a new field from an expression. I have a survey123 form feature layer where I am collecting pump hour readings twice a week and I want to calculate run hours from the current reading  from the previous reading. Does anyone have a script for this? I am struggling to get the difference between a current date reading and a previous date reading. HELP???

 

 

TomKukitz_0-1695053294679.png

 

Thanks!

Tom

Tags (2)
0 Kudos
2 Replies
EmilyGeo
Esri Contributor

Hi @TomKukitz

you can calculate the difference between two dates using the DateDiff function in Arcade. You can find more information about it in the reference documentation here

Basically this function calculates the amount of time between two dates in the units that you choose (minutes, hours, days, months, years, etc). Here is a sample code block: 

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

0 Kudos
TomKukitz
New Contributor III

Thank you, I really appreciate it!

I get that time diff part, but I need to display the etmhours field attribute. So in essence I am get hours from one date and subtract from another date. It would be curretm - prevetm. Current date would be the last and most current date, subtracted from the second last current date or the previous to current. I hope I didn't totally confuse you now???!!! Any ideas on how to accomplish this? I am trying to avoid writing a 10 page script as well. Things take forever with Arcade, I so miss attribute assistant, so much easier in VB.

Any input much appreciated!

0 Kudos