English

How To: Extract and insert a portion of the date field in a new field in ArcGIS Pro

Summary

It is possible to extract a portion of the date field in an attribute table for data analysis and insert it in a new field using the Calculate Field geoprocessing tool in ArcGIS Pro.

Procedure

The following steps describe how to extract and insert a portion of the date field (year, month, or day) in a new field using Arcade expression in the Calculate Field geoprocessing tool in ArcGIS Pro:

  1. Add a new field in the attribute table. Refer to ArcGIS Pro: Create a field and apply a domain and default value for steps to do this.
    1. Set the Data Type to Short.
    2. Leave all other parameters at default.
    3. On the ArcGIS Pro ribbon, in the Fields tab, click Save.
  2. Open the Calculate Field geoprocessing tool.
    1. Navigate to the Analysis tab, and click Tools.
    2. In the Geoprocessing pane, click Toolboxes > Data Management Tools > Fields > Calculate Field.
  3. Create an Arcade expression in the Calculate Field tool to extract a desired date portion (year, month, or day) from the date field.
    1. In the Calculate Field window, click Parameters.
    2. In Input Table, select the layer with the attribute table containing the date field.
    3. In Field Name, select the newly created field from step 1.
    4. In Expression Type, select Arcade.
Calculate field window
  1. Under Helpers, double-click the portion of the date field to be extracted: Year(), Month(), or Day().
  2. In the box under the new field selected in step 3c, place the cursor in the middle of the brackets of the selected Helper function as shown in the example below.
Year function screenshot
  1. Under Fields, double-click the date field containing the desired date portion. The following shows the created Arcade expression:
<DATE_PORTION>($feature.<DATE_FIELD>)
Date field inserted in the Year function.
  1. Click the Validate symbol Validate icon., to validate the Arcade expression.
  2. Click Run Run button.

The desired date portion is extracted from the date field, and inserted into the newly created field.

Note:
The output of the Arcade expression using the Month() function returns values ranging from 0-11 where January is 0 and December is 11. Refer to the additional steps below to change the values range to 1-12,  where January is 1 and December is 12.
  1. Use a Python expression to change the month values range to 1-12 using the Calculate Field tool.
    1. In Input Table, select the layer with the attribute table that contains the extracted month field in step 3.
    2. In Field Name, select the extracted month field, the output of the Arcade expression from step 3.
    3. In Expression Type, select Python 3.
    4. In the box under the selected field name in step 4b, insert the following syntax:
!<FIELD_NAME>! + 1
Calculate field window
  1. Click the Validate symbol Validate icon, to validate the Python expression.
  2. Click Run Run button.

The month values are displayed in the new field.

The image below shows the year, month, day portion extracted and inserted in new fields.

Attribute table with extracted date portion

Related Information

Last Published: 8/8/2019

Article ID: 000021112