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 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

arcpy.management.ConvertTimeField(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.

Note:

The format strings are case sensitive.

  • If the data type of the time field is date, no time format is required.
  • 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. Some commonly used formats are listed below:
    • yyyy - Year represented by four digits.
    • MM - Month as digits with leading zero for single-digit months.
    • MMM - Month as a three-letter abbreviation.
    • dd - Day of month as digits with leading zero for single-digit days.
    • ddd - Day of week as a three-letter abbreviation.
    • hh - Hours with leading zero for single-digit hours; 12-hour clock.
    • HH - Hours with leading zero for single-digit hours; 24-hour clock.
    • mm - Minutes with leading zero for single-digit minutes.
    • ss - Seconds with leading zero for single-digit seconds.
    • t - One character time marker string, such as A or P.
    • tt - Multicharacter time marker string, such as AM or PM.
    • unix_us - Unix time in microseconds.
    • unix_ms - Unix time in milliseconds.
    • unix_s - Unix time in seconds.
    • unix_hex - Unix time in hexadecimal.

Learn more about custom dates and time formats

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.

  • 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. 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.

Note:

If the data type of the output time field isn't long enough to store the converted time value, the output value will be truncated.

String

Derived Output

NameExplanationData Type
out_table

The updated input table.

Table View

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

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics