How To: Extract and insert a portion of the date field in a new field in ArcGIS Pro
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.
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:
- 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.
- Set the Data Type to Short.
- Leave all other parameters at default.
- On the ArcGIS Pro ribbon, in the Fields tab, click Save.
- Open the Calculate Field geoprocessing tool.
- Navigate to the Analysis tab, and click Tools.
- In the Geoprocessing pane, click Toolboxes > Data Management Tools > Fields > Calculate Field.
- Create an Arcade expression in the Calculate Field tool to extract a desired date portion (year, month, or day) from the date field.
- In the Calculate Field window, click Parameters.
- In Input Table, select the layer with the attribute table containing the date field.
- In Field Name, select the newly created field from step 1.
- In Expression Type, select Arcade.
- Under Helpers, double-click the portion of the date field to be extracted: Year(), Month(), or Day().
- 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.
- Under Fields, double-click the date field containing the desired date portion. The following shows the created Arcade expression:
- Click the Validate symbol , to validate the Arcade expression.
- Click Run .
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.
- Use a Python expression to change the month values range to 1-12 using the Calculate Field tool.
- In Input Table, select the layer with the attribute table that contains the extracted month field in step 3.
- In Field Name, select the extracted month field, the output of the Arcade expression from step 3.
- In Expression Type, select Python 3.
- In the box under the selected field name in step 4b, insert the following syntax:
!<FIELD_NAME>! + 1
- Click the Validate symbol , to validate the Python expression.
- Click Run .
The month values are displayed in the new field.
The image below shows the year, month, day portion extracted and inserted in new fields.
- ArcGIS Pro: Create a field and apply a domain and default value
- ArcGIS Pro: Date fields
- How To: Extract a portion of the Date field
Last Published: 8/8/2019
Article ID: 000021112