HOW TO

Create a new date field with milliseconds in ArcGIS Pro

Last Published: July 5, 2023

Summary

In ArcGIS Pro, Python expressions can be used to create a new date field with milliseconds from a specified text data type field with date and time values. This article provides an example and instructions to create a new date data type field by referencing the text field with date and time values using Python expressions in ArcGIS Pro.

The image below shows the attribute table with the text data type date and time field.

The attribute table in ArcGIS Pro

Procedure

  1. In the Contents pane, right-click the feature class and click Attribute Table to open the attribute table of the feature class.
Opening the attribute table of the feature class from the Contents pane
  1. Click Calculate to open the Calculate Field tool.
Note:
Refer to ArcGIS Pro: Calculate Field (Data Management) for more information on the parameters in the Calculate Field tool.
  1. In the Calculate Field dialog box, configure the following parameters:
    1. For Input Table, select the feature class.
    2. For Field Name (Existing or New), select the field to be edited or create a new field. In this example, the CreationDate field is created.
    3. For Field Type, select Date.
    4. For Expression Type, select Python 3.
    5. Specify the following expression in the first code block. In this example, <textField> is named CreationDateText.
Note:
The date format and separators must be replicated in accordance to the referenced datetime text field. For example, if the datetime text field is displayed as '2023/05/11', specify the datetime Python 3 script as "%Y/%m/%d %H:%M:%S.%f".
datetime.datetime.strptime(!<textField>!, "%d-%m-%Y %H:%M:%S.%f")
    1. Click Verify to run a test of the expression. If the expression is valid, click OK.
The Calculate Field tool pane with the parameters to be filled
  1. In the Contents pane, right-click the feature class, and click Data Design > Fields to open the fields view of the feature class.
Opening the fields view of the feature class from the Contents pane
  1. Click the cell in the Number Format column for the row of the target field to format.
  2. In the highlighted cell, click the Options button The Options icon to open the Number Format dialog box.
The Options icon in the fields view
  1. In the Number Format dialog box, click the Format drop-down menu and select Custom.
  2. In the Custom date format text box, edit the date and time format specifiers as required. In this example, dd.MM.yyyy HH:mm:ss.s is used. Refer to ArcGIS Pro: Date and time formats for more date and time format specifiers.
  3. Click OK and Save on the ArcGIS Pro ribbon in the Changes group.

The image below shows the new date field with milliseconds added to the attribute table.

The attribute table with the new date field added

Article ID: 000030755

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 9x

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