HOW TO

Populate a date field using values from a text field in ArcGIS Online

Last Published: December 13, 2021

Summary

The instructions provided in this article describe the steps to populate a date field using values from a text field using Arcade expression in ArcGIS Online. The example applies the date format 'YYYY/MM/DD, Local Time'.

Procedure

  1. Log in to ArcGIS Online.
  2. Navigate to Content > My Content, and select the desired feature layer.
  3. In the feature layer page, click Data to open the attribute table. The following is a sample of an attribute table, with IntakeDate field containing the text data type values representing the dates.
Attribute table containing a Text field with date value
  1. Add a new Date field to the attribute table by clicking the Options button The Options button in ArcGIS Online attribute table > Add Field.
Adding new field in an attribute table in ArcGIS Online
  1. Click the header of the new field and select Calculate.
  2. In the Calculate Field pane, select Arcade.
Select Arcade
  1. Under Expression, run the following script. In this example, the date format is MM/DD/YYYY, local time, based on how the Date() and ToLocal() function works.
    var date_text = $feature.IntakeDate //replace this parameter with the desired field

    function Convert2Date(date_text){

         var months = {"01": 0, "02": 1, "03": 2, "04": 3, "05": 4, "06": 5, "07": 6, "08": 7, "09": 8, "10": 9, "11": 10, "12": 11};

         var date_list = Split(date_text, '/')

         var yearNum = Number(date_list[0]);

         var monthNum = months[date_list[1]];

         var dayNum = Number(date_list[2]);

         return Date(yearNum,monthNum,dayNum);
    }

    return ToLocal(Convert2date(date_text));
  1. Click Test to ensure the script runs and returns the desired value. The Result section shows the field value. Click OK to save the settings.
Date value result from running the Arcade script

The image below shows the new date field, LocalDate, is populated.

New date field is populated with the values

Article ID: 000026844

Software:
  • ArcGIS Online

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