Summary
Adds fields containing date or time properties from an input date field, for example, day full name, day of the month, month, and year.
Usage
-
Existing fields will be overwritten in the Input Table when an existing field name is the same as the defined Output Field Name.
The values of the new fields will not update automatically if the values of the Date Field are updated. Run this tool when the Date Field is updated.
Syntax
AddDateAttributes(in_table, date_field, date_attributes)
Parameter | Explanation | Data Type |
in_table | The layer or table that contains the field with the date values that need to be extracted. | Table View |
date_field | The date field from which data and time properties will be extracted to populate the new field values. | Field |
date_attributes [date_attributes,...] | Specifies the date and time properties and fields that will be added to the input table.
Output Time Format options are as follows:
| Value Table |
Derived Output
Name | Explanation | Data Type |
out_table | The updated input table containing the date attributes. | Table View |
Code sample
The following Python window script demonstrates how to use the AddDateAttributes function in immediate mode.
import arcpy
arcpy.env.workspace = r"C:\data\city_pd.gdb"
arcpy.ca.AddDateAttributes("CallsForService", "CALLDATE")
The following Python script demonstrates how to use the AddDateAttributes function in a stand-alone script.
# Name: AddDateAttributes.py
# Description: Adds fields for hour, day full name, month, day of the month,
# and year to the calls for service data based on the call date
# field.
# Import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = r"C:/data/city_pd.gdb"
# Set local variables
in_features = "CallsForService"
date_field = "CALLDATE"
# Customize the name of output date attribute fields
# ["Output Time Format", "Output Field Name"]
day_name_field = ["DAY_FULL_NAME", "CALL_DAYOFWEEK"]
hour_field = ["HOUR", "CALL_HOUR"]
month_field = ["MONTH", "CALL_MONTH"]
day_num_field = ["DAY_OF_MONTH", "CALL_DAY"]
year_field = ["YEAR", "CALL_YEAR"]
date_attributes = [day_name_field, hour_field, month_field, day_num_field,
year_field]
# Execute AddDateAttributes
arcpy.ca.AddDateAttributes(in_features, date_field, date_attributes)
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes