Add Date Attributes (Crime Analysis and Safety)

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 value when an existing field name is the same as the defined Output Field Name value.

  • The values of the new fields will not update automatically if the values of the Date Field parameter are updated. Run this tool when the Date Field parameter is updated.

Parameters

LabelExplanationData Type
Input Table

The layer or table that contains the field with the date values that will 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

The date and time properties and fields that will be added to the input table.

  • Output Time Format—The date or time property that will be added to Output Field Name.
  • Output Field Name—The name of the field that will be added to the input table.

The Output Time Format options are as follows:

  • Hour—The hour value between 0 and 23.
  • Day Full Name—The full name of the day of the week, for example, Wednesday.
  • Day Numeric Value—The day of the week value between 1 and 7.
  • Month—The month value between 1 and 12.
  • Day of the Month—The day of the month value between 1 and 31.
  • Year—The year value in yyyy format, for example, 1983.
Value Table

Derived Output

LabelExplanationData Type
Updated Input Table

The updated input table containing the date attributes.

Table View

arcpy.ca.AddDateAttributes(in_table, date_field, date_attributes)
NameExplanationData Type
in_table

The layer or table that contains the field with the date values that will 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,...]

The date and time properties and fields that will be added to the input table.

  • Output Time Format—The date or time property that will be added to Output Field Name.
  • Output Field Name—The name of the field that will be added to the input table.

The Output Time Format options are as follows:

  • Hour—The hour value between 0 and 23.
  • Day Full Name—The full name of the day of the week, for example, Wednesday.
  • Day Numeric Value—The day of the week value between 1 and 7.
  • Month—The month value between 1 and 12.
  • Day of the Month—The day of the month value between 1 and 31.
  • Year—The year value in yyyy format, for example, 1983.
Value Table

Derived Output

NameExplanationData Type
out_table

The updated input table containing the date attributes.

Table View

Code sample

AddDateAttributes example 1 (Python window)

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")
AddDateAttributes example 2 (stand-alone script)

The following Python script demonstrates how to use the AddDateAttributes function in a stand-alone script.

# Name: AddDateAttributes.py
# Description: Add 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"]
day_week_field = ["DAY_OF_WEEK", "CALL_DAYNUM"]
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, day_week_field, hour_field, month_field, day_num_field, 
                   year_field]

# Execute AddDateAttributes
arcpy.ca.AddDateAttributes(in_features, date_field, date_attributes)

Licensing information

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

Related topics