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 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)
ParameterExplanationData 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—The date or time property to be added to the Output Field Name.
  • Output Field Name—The name of the field that will be added to the input table.

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

Licensing information

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

Related topics