HOW TO

Convert the 24-hour time format string value to the 12-hour format in ArcGIS Enterprise and ArcGIS Online Map Viewer

First Published: October 10, 2023
Last Published: April 3, 2026

Summary

At times, it is necessary to convert the 24-hour time format string values to the 12-hour format (AM or PM). However, it is time-consuming if the data provided is large, 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 steps to convert the 24-hour time format string values to a 12-hour format using an Arcade expression in ArcGIS Enterprise and ArcGIS Online Map Viewer.

The time in the attribute table in 24-hour format

Procedure

Note:
This workflow only applies to time data in a text field. For time data in a date field, use the Convert Temporal Field (Data Management) tool in ArcGIS Pro to convert the date field to a text field.
  1. Log in to the ArcGIS Enterprise portal or ArcGIS Online and click Content > My content.
  2. Browse to and click the hosted feature layer to open the item page.
  3. Click the Data tab to show the table.
  4. Convert the time to the 12-hour format using an Arcade expression.
    1. Click the field header of the time field, and select Calculate from the drop-down list.
    2. For Select language, select Arcade and click Next.
    3. Copy and paste the following expression into the Arcade expression box. Replace <TIME_FIELD> with the name of the time field. Click Run.
var t = ($feature.<TIME_FIELD>)

var h = Number(Split(t, ":", 2)[0]);
var m = Split(t, ":", 2)[1];
var AMPM = When( 
h > 12, h - 12,
h == 0, 12,
h );
var suffix = When(
h == 24, " AM",
h >= 12, " PM",
" AM" );
Concatenate( [ AMPM, m ], ":" ) + suffix;
The Arcade expression configured in the Arcade expression box
  1. When the Output tab displays the time in the 12-hour format, click Run calculation.
The 12-hour time format on the Output tab

The attribute table below shows the time in the 12-hour format.

The 24-hour time format converted to a 12-hour time format in the attribute table.

Article ID: 000031184

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options