English

How To: Extract a portion of the Date field

Summary

Individual portions in a Date field of a feature class or shapefile, such as year, month, day, hour, minute, or second, can extracted using the DatePart() VB function in the Field Calculator.

Note:
Note that only the date portion (yyyy/mm/d) is supported in shapefile attributes, therefore, no time information (hh:mm:ss) can be extracted from a shapefile Date field.

Procedure

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward
  1. Add a new field to the target feature class or shapefile. Specify the field type as Text. The Date field does not support a single date portion, so the portion should be extracted to a Text field. See: Adding fields instructions
  2. Open the Field Calculator for the new field following steps in this help page: Making simple field calculations
  3. In the Field Calculator, enter:
    DatePart("PART", [DATEFIELD])
    The PART argument can be one of the following keywords: yyyy (YEAR), m (MONTH), d (DAY), h (HOUR), n (MINUTE), or s (SECOND), and it must be enclosed with double quotation marks.
  4. Click OK to run the field calculation. 

    User-added image

Related Information

Last Published: 9/16/2019

Article ID: 000014933

Software: ArcMap 10.4.1, 10.4, 10.3.1, 10.3, 10.2.2, 10.2.1, 10.2, 10.1, 10