[GIS] Selecting by month in date/time field using ArcGIS Desktop

arcgis-desktopdateselect-by-attribute

I would like to select by a specific month from my date/time field in ArcGIS, and just can't seem to find a statement that will work.

I have multiple years and multiple days, but want to filter those out and only choose the records from the month of May.

Best Answer

The syntax varies depending on where the data is being fetched from (file gdb, shapefile, personal gdb, Oracle, DB2, etc.).

File Geodatabase, shapefiles, and file-based data such as dbf files:

Everything in May:

EXTRACT(MONTH FROM "MyDate") = 05

Before noon:

EXTRACT(HOUR FROM "MyDate") < 12

Personal Geodatabase (.mdb):

DATEPART("m", [MyDate]) = 05

SQL Server:

DATEPART(month, MyDate) = 05

For more details such as further limitations and query by hour/year/etc. see the Esri HowTo: Search for specific parts of a date stored in a Date-Time field. For extended examples using Field Calculator see ArcWatch Simplify Date and Time Calculations.