HOW TO

Round time to the nearest hour in a text field using Arcade in Portal for ArcGIS and ArcGIS Online Map Viewer

Last Published: May 23, 2024

Summary

At times, it is necessary to remove the minutes and seconds recorded in the time field. However, rounding the time to the nearest hour is time-consuming if a large data is provided as shown in the image below. This is resolved by using an Arcade expression to populate the data in the attribute table. This article provides the workflow to round the time to the nearest hour using an Arcade expression in Portal for ArcGIS and ArcGIS Online Map Viewer.

The time with minutes and seconds included in the attribute table.

Procedure

Note:
This workflow only applies to time data in a text field. For time data in a date field, use the Convert Time Field (Data Management) tool in ArcGIS Pro to convert the date field to a text field.
  1. Log in to Portal for ArcGIS or ArcGIS Online and click Content > My Content.
  2. Browse to and click the hosted feature layer to open the item details page.
  3. Click the Data tab to show the table.
  4. Round the time off to the nearest hour using an Arcade expression.
    1. Click the field header of the time field, and select Calculate from the drop-down list. Click Arcade.
    2. Copy and paste the following Arcade expression into the Expression box. Replace <TIME_FIELD> with the name of the time field. Click Test.
var t = ($feature.<TIME_FIELD>)
var x = Iif (Minute(t) < 30, Hour(t), Hour(t) + 1)
if(x == 24) {
return 0 + ":00";
} else {
return x + ":00"}
The Arcade expression configured in the Expression box.
  1. When the Results tab displays the time rounded off, click OK.
The time rounded off displayed on the Results tab.

The image below shows the time rounded off to the nearest hour in the 24-hour time format in the Portal for ArcGIS attribute table.

The time rounded off in the attribute table.

Article ID: 000030915

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1

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

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options