Convert Time Field (Data Management)

Summary

Transfers date and time values stored in a field to another field. The tool can be used to convert between different field types (text, numeric, or date fields) or to convert the values to a different format such as dd/MM/yy HH:mm:ss to yyyy-MM-dd.

Usage

Parameters

LabelExplanationData Type
Input Table

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

Table View
Input Time Field

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

Field
Input Time Format
(Optional)

The format of the time values in the Input Time Field parameter value. Either a standard time format can be selected from the drop-down list or a custom format can be manually entered. The parameter is not supported when the input time field is of type date.

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

String
Output Time Field Name

The name of the field to be added, into which the converted time values will be stored.

String
Output Time Field Type
(Optional)

Specifies the field type of the output time field.

  • DateThe field type will be date. Date fields support date and time values.
  • TextThe field type will be text. Text fields support a string of characters.
  • Long (large integer)The field type will be long. Long fields support whole numbers between -2,147,483,648 and 2,147,483,647.
  • Short (small integer)The field type will be short. Short fields support whole numbers between -32,768 and 32,767.
  • Double (double precision)The field type will be double. Double fields support fractional numbers between -2.2E308 and 1.8E308.
  • Float (single precision)The field type will be float. Float fields support fractional numbers between -3.4E38 and 1.2E38.
String
Output Time Format
(Optional)

The format of the output time values. Supported output time formats depend on the Output Time Field Type parameter value. A custom format can also be used to convert the value to a different format or to extract a portion of the value (such as the year). For a list of custom formats, see the Input Time Format parameter help. This parameter is not used when the Output Time Field Type parameter value is Date.

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

LabelExplanationData Type
Updated Input Table

The updated input table.

Table View

arcpy.management.ConvertTimeField(in_table, input_time_field, {input_time_format}, output_time_field, {output_time_type}, {output_time_format})
NameExplanationData Type
in_table

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

Table View
input_time_field

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

Field
input_time_format
(Optional)

The format of the time values in the input_time_field parameter value. The parameter is not supported when the input time field is of type date.

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

String
output_time_field

The name of the field to be added, into which the converted time values will be stored.

String
output_time_type
(Optional)

Specifies the field type of the output time field.

  • DATEThe field type will be date. Date fields support date and time values.
  • TEXTThe field type will be text. Text fields support a string of characters.
  • LONGThe field type will be long. Long fields support whole numbers between -2,147,483,648 and 2,147,483,647.
  • SHORTThe field type will be short. Short fields support whole numbers between -32,768 and 32,767.
  • DOUBLEThe field type will be double. Double fields support fractional numbers between -2.2E308 and 1.8E308.
  • FLOATThe field type will be float. Float fields support fractional numbers between -3.4E38 and 1.2E38.
String
output_time_format
(Optional)

The format of the output time values. Supported output time formats depend on the output_time_type parameter value. A custom format can also be used to convert the value to a different format or to extract a portion of the value (such as the year). For a list of custom formats, see the input_time_format parameter help. This parameter is not used when the output_time_type parameter value is DATE.

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

# 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