Convert Time Field (Data Management)

License Level:BasicStandardAdvanced

Summary

Converts time values stored in a string or numeric field to a date field. The tool can also be used to convert time values stored in string, numeric, or date fields into custom formats such as day of the week, month of the year, and so on.

Illustration

Converting string or numeric field containing time values into a date field
In the illustration, the time values stored as strings in the Input_Time field that were collected in the format MMMM d, yyyy HH:mm:ss have been converted into time values stored as date values in the Output_Time field.

Usage

Syntax

ConvertTimeField_management (in_table, input_time_field, {input_time_format}, output_time_field, {output_time_type}, {output_time_format})
ParameterExplanationData Type
in_table

The layer or table that contains the field containing the time values that need to be converted.

Table View
input_time_field

The field containing the time values. May be of type short, long, float, double, text, or date.

Field
input_time_format
(Optional)

The format in which the time values were stored in the input time field. Either a standard time format can be selected from the drop-down list, or a custom format can be entered. If the data type of the time field is numeric (Short, Long, Float, or Double), a list of standard numeric time formats is provided in the drop-down list. If the data type of the time field is string, a list of standard string time formats is provided in the drop-down list. For string fields, you can also choose to specify a custom time format. For example, the time values may have been stored in a string field in one of the standard formats such as yyyy/MM/dd HH:mm:ss or in a custom format such as dd/MM/yyyy HH:mm:ss. For the custom format, you can also specify the a.m., p.m. designator.

If the data type of the time field is date, then no time format is required.

Learn more about custom dates and time formats

String
output_time_field

The name of output field in which the converted time values will be stored.

String
output_time_type
(Optional)

The data type of the output time field.

  • DATEDate and/or time.
  • TEXTAny string of characters
  • LONGWhole numbers between -2,147,483,648 and 2,147,483,647.
  • SHORTWhole numbers between -32,768 and 32,767.
  • DOUBLEFractional numbers between -2.2E308 and 1.8E308.
  • FLOATFractional numbers between -3.4E38 and 1.2E38.
String
output_time_format
(Optional)

The format in which the output time values will be saved. The list of output time formats depends on the output data type specified for the output time field.

String

Code Sample

ConvertTimeField example 1 (Python window)

The following Python window script demonstrates how to use the ConvertTimeField tool in immediate mode.

import arcpy
arcpy.ConvertTimeField_management("C:/Data/TemporalData.gdb/Input_Table","Input_Time","1033;MMMM dd, yyyy HH:mm:ss;AM;PM","Output_Time")
ConvertTimeField example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the ConvertTimeField tool.

# Name: ConvertTimeField_Ex02.py
# Description: Convert a time field to date field
# Requirements: None

# Import system modules
import arcpy

# Set local variables
inTable = "C:\Data\TemporalData.gdb\Input_Table"
inputTimeField = "Input_Time"
inputTimeFormat = "1033;MMMM dd, yyyy HH:mm:ss;AM;PM"
outputDateField = "Output_Time"

# Execute CalculateEndDate
arcpy.ConvertTimeField_management(inTable, inputTimeField, inputTimeFormat, outputDateField)

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015