Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
Where is your data stored? fGDB? shapefile? SQL Server? Oracle? –  Derek Swingley Apr 5 '11 at 20:54
    
How are you searching for the data? I know there is a bug where the time element of datetime doesn't show if the time is midnight. Remember, too, that locale is important in the order of data, months, especially so. There are a whole host of operations you can use in Python or VBS to disseminate date data, as well as on the Oracle side (Between, etc...). –  Hairy Apr 6 '11 at 10:18
    
Data is stored in a shapefile. –  user2595 Apr 6 '11 at 15:21
    
thank you! was useful - I did my selection by dates very quickly! –  user5133 Dec 13 '11 at 0:20
    
welcome to GIS.StackExchange. The "Your Answer" is meant for potential answers to the question at hand, not comments. Feel free to leave a comment under the answer that worked best for you, and press the "upvote" button to give more credibility to that answer. That way new readers will be able to guage which answer is most likely to help. –  RyanDalton Dec 13 '11 at 0:37

7 Answers 7

You should be able to use the appropriate database function to query out the month from the date field. For example, in Oracle you could select by attribute where To_Char([date],'MM') = 4.

share|improve this answer

Try something like...
Select DatePart(MM, GetDate()) as Current_Month

share|improve this answer

Horrible hack, but you could export your attribute table to .csv; import into Excel, and parse the year/month/day in excel. Then join that Excel worksheet to your table, and sort on the month.

share|improve this answer

A simple script to write would be to get the date in it's entirety, then split it:

Time = "2011-04-06 11:26:51" Month = newTime.split("-")[1]

Then do your comparison on the Month value

share|improve this answer

Perhaps something like this:

  1. Open the shapefile attribute table and click Options > Select By Attributes
  2. Type DatePart("M", [YourDateField]) = 5 (for May) and click Apply.

Good luck!

share|improve this answer
    
This code sample works really well. I actually used it to calc a new field values for month based upon the Month DatePart. –  RyanDalton Apr 6 '11 at 21:26

In ArcGIS 10 (probably works similarly in earlier versions in the select by attributes tool you can specify the selection statement to have a range between the beginning of the month and the end of the month, but the syntax in ArcMap is strange.

The selection query should look like this:

"DateField" >= date '05/01/2011 00:00:00' AND "DateField" < date '06/01/2011 00:00:00'

I used excel to make a long list of month ranges and then used model builder to make a script to batch select by the above query, update an ‘order by’ field, and then export to a standalone filegeodatabase featureclass.

share|improve this answer
    
my source data is in a file geodatabase. –  Max Squires Apr 10 '11 at 17:11
1  
This works! It is too bad that you would have to write it out for EACH year in the dataset. Thanks! –  user2595 Apr 11 '11 at 15:14

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.