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 and month of the year.
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 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
ConvertTimeField_management (in_table, input_time_field, {input_time_format}, output_time_field, {output_time_type}, {output_time_format})
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.
| String |
output_time_field | The name of the output field in which the converted time values will be stored. | String |
output_time_type (Optional) | The data type of the output time field.
| 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. A custom format can also be used when the data type of the output time field is not Date. For a list of custom formats, see the explanation of Input Time Format. | 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.
Licensing information
- ArcGIS Desktop Basic: Yes
- ArcGIS Desktop Standard: Yes
- ArcGIS Desktop Advanced: Yes