HOW TO

Remove dates before current date in an attribute table using Arcade in Portal for ArcGIS and ArcGIS Online

Last Published: May 9, 2024

Summary

In an attribute table containing a date field for a feature layer in Portal for ArcGIS and ArcGIS Online, removing expired dates from today's date is important for data accuracy as inconsistencies can lead to errors.

This article describes the workflow to remove dates before the current date in an attribute table using an Arcade expression in Portal for ArcGIS and ArcGIS Online.

In this example, the attribute table contains invalid dates considering today's date is January 26, 2024.

The attribute table contains invalid dates

Procedure

  1. Log in to Portal for ArcGIS or ArcGIS Online and click Content > My Content.
  2. Click the hosted feature layer containing the date field to open the item details page.
  3. Calculate the field to remove invalid dates using Arcade. In this example, the 'Expired' field is selected. Refer to Portal for ArcGIS: Calculate values for a field or ArcGIS Online: Calculate values for a field for instructions.
  4. In the Expression window, specify the following Arcade expression:
    1. Get the current date and time.
var today = Now();
  1. Retrieve the value of the date field from the attribute table.
var expirationDate = $feature['Expired'];
  1. Check and delete if the expiration date is before today's date.
if (expirationDate < today) {
    return null;
} else {
    return expirationDate;
}

The code block below shows the full working script.

var today = Now();
var expirationDate = $feature['Your_Date_Field'];
if (expirationDate < today) {
    return null;
} else {
    return expirationDate;
}
  1. Click OK.

The image below shows the attribute table after removing the invalid dates.

The invalid dates are removed

Article ID: 000032562

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2

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