Convert Time Field (Data Management)
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
Usage
-
If the input time field selected is a string or text field, the input time format can be selected from a list of supported time field formats. or you can define a custom time field format to interpret custom date and/or time values in the string field. For more information about custom formats for string fields, see converting string time values into date format.
If the input time field selected is numeric (short, long, float, or double), the input time format can be selected from a list of supported standard time field formats. Custom time formats are not supported with numeric fields.
Syntax
Parameter | Explanation | Data 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. | 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. May be of type short, long, float, double, text, or date. | 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
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")
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)