操作方法

操作方法:在 ArcGIS Pro 中移除日期字段中的时间戳

Last Published: October 17, 2024

摘要

In certain cases, when loading new data, the date field is displayed in the format yyyy-mm-dd hh:mm:ss AM/PM. However, there may be instances where displaying the timestamp alongside the date is unnecessary. This article provides instructions to remove the timestamp from the date field in the attribute table in ArcGIS Pro.

过程

Use one of the methods below to remove the timestamp from the date fields in the attribute table in ArcGIS Pro.

Create a new Date Only field

Note:
This workflow is only applicable to ArcGIS Pro 3.2 and later.
  1. In ArcGIS Pro, open the attribute table of the layer.
  2. In the attribute table, click the Add button to add a new field.
  3. Fill in the new field name and alias for Field Name and Alias.
  4. Select Date Only for Data Type. Refer to ArcGIS Pro: Add Field (Data Management) for more information. Click Save.

The image of the new field with a Date Only field.

  1. In the attribute table, right-click the new field heading, and click Calculate Field.
  2. In the expression box, double-click the original date field under Fields.
  3. Click Apply > OK.

The image of the new field being calculated using the original date field.

Use the Field Calculator (Python) function

  1. In ArcGIS Pro, open the attribute table of the layer.
  2. In the attribute table, right-click the desired field heading, and click Calculate Field.
  3. In the Calculate Field window, select the feature layer for Input Table, the field name for Field Name (Existing or New), and Python for Expression Type.
  4. In the expression box, copy and paste the following script and replace FieldName accordingly.
FindDate(!FieldName!)
  1. In the Code Block box, copy and paste the following script:
def FindDate(date):
    if date is None:
        return None
    else:
        return str(date).split(" ").pop(0)
  1. Click Apply > OK.
The Calculate Field window with the Python scripting.
Note:
Alternatively, in the expression box, copy and paste the following script and replace FieldName accordingly.

timestamp(!FieldName!)

In the Code Block box, copy and paste the following script:

from datetime import datetime

def timestamp(mydate):
 date = mydate
 strdate = date.strftime("%Y/%m/%d")
 finaldate = datetime.strptime(strdate,"%Y/%m/%d")
 return finaldate

The following image shows the date field with only the date displayed in the attribute table.

The date field showing results of the timestamp removed.

Use the Convert Temporal Field tool

Note:
Using the Convert Temporal Field tool creates a new field in the attribute table.
  1. In ArcGIS Pro, on the Analysis tab, click Tools in the Geoprocessing group.
  2. In the Geoprocessing pane, search for and select Convert Temporal Field.
  3. In the Convert Temporal Field pane, in Parameters, select the input table or layer and input date field for the Input Table and Input Field boxes.
  4. In the Output Field Name box, fill in the output field name.
  5. In the Output Field Type box, select Date only to display the output date format selection.
Note:
If Text is selected, select the date format without the timestamp for Output Format.
  1. Click Run.
The Convert Time Field tool used to set the date format.

The following image shows the newly created date field with only the date displayed.

The newly created date field with the timestamp removed.

文章 ID: 000025447

接收通知并查找新问题或常见问题的解决方案

从我们全新的 AI 聊天机器人中获得简明答案和视频解决方案。

下载 Esri 支持应用程序

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项