HOW TO

Convert decimal time to a duration of hours, minutes, and seconds

Last Published: August 24, 2023

Summary

In ArcGIS Pro, decimal time can be converted to hours, minutes, and seconds using the Convert Time Field tool and the Calculate Field tool. However, in some instances, the result of the Convert Time Field tool represents a point of time and is stored in a date field as datetime yyyy-mm-dd hh:mm:ss AM or PM. This article provides the workflow to convert decimal time to a duration of time represented in hours, minutes, and seconds using the Calculate Field tool. The result of this workflow is stored in a text field.

Procedure

  1. In ArcGIS Pro, in the Contents pane, right-click the layer containing the decimal time, and select Attribute Table.
  2. In the table view pane, right-click the decimal time field, and select Calculate Field. In this example, the field is DecimalTime.
Open the Calculate Field window by right-clicking the header of the decimal time field, and select Calculate Field from the list.
  1. In the Calculate Field window, for Field Name, click the drop-down arrow to select an existing field, or type a new name to populate the calculation output in a new field. In this example, the name of the new field is Hms.
  2. In the expression box, type the code provided below. Replace 'Field Name' with the name of the decimal time field.
str(int(!Field Name!))+"h "+str(round((!Field Name!*60) % 60))+"m "+str(round((!Field Name!*3600)% 60))+"s"
Note:
Do not remove the exclamation marks surrounding the field name. Custom texts or spacing can be replaced in the double quotation marks (" ") if required.
  1. Click Apply.
  2. Click OK to close the Calculate Field window.
To perform the calculation, in the Calculate Field window, type a name in the Field Name section to create a new field for the output or click the drop-down arrow to select an existing field (Step 3). Copy and paste the expression in the box (Step 4). At the bottom of the window, click the Apply button on the left to run the calculation (Step 5). Click the OK button on the right to close the window (Step 6).

The output is populated in the new text field in a custom format of hours, minutes, and seconds.

In the table view pane, the output of the calculation is populated in the new field Hms, the duration of time is displayed in the custom format of h, m, and s.

Article ID: 000026666

Software:
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 x

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