HOW TO

Calculate the difference between two date fields using Arcade in ArcGIS Pro

Last Published: July 21, 2023

Summary

Arcade is an expression language that can be used across the ArcGIS platform. The Arcade Date functions provide methods to create and acquire properties of date objects. For example, the DateAdd() and DateDiff() functions can be used to adjust the date based on specified intervals, and the Now() function to obtain the client's local time.

This article provides the workflow to calculate the difference between two date fields using the Arcade DateDiff() function.

Procedure

  1. In ArcGIS Pro, open the attribute table containing the two date fields.
  2. Create a new integer field in the attribute table using the Add Field tool.
  3. In the attribute table, right-click the new field, and click Calculate Field to calculate the difference between the two date fields.
    1. In the Calculate Field pane, select the attribute table containing the date fields for Input Table.
    2. Ensure the new field is selected for Field Name.
    3. For Expression Type, select Arcade.
    4. In the expression text box, type the following expression to calculate the difference in minutes, and replace startDateField and endDateField with their respective field names.
var startDate = Date($feature.startDateField)
var endDate = Date($feature.endDateField)
var result = DateDiff(endDate, startDate, 'minutes')
return result
The image of Calculate Field pane.
Note:
To calculate the difference between the two date fields in other units, such as hours, seconds, or days, use the same expression and replace 'minute' with the desired unit of measurement.
  1. Click Run to apply the expression. The difference in minutes between the two date fields is calculated and populated in the new field.
The image of the calculated time difference.

Article ID: 000023627

Software:
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options