Select to view content in your preferred language

Creating filter based on date only of date/time field

161
4
a week ago
Labels (2)
RileyScanlan
New Contributor II

I am trying to calculate a field in my table that is the sum of field GRID_COUNT in a feature class called 'HWA_GRIDS_TREATMENT_local',  for all rows where the date of layer ''HWA_GRIDS_TREATMENT_local' matches the date in my table. The date fields are supposed to be date only but have time info, so I am trying to pull just the year, month and date in my filters. 

Apologies for the unhelpful variable naming but hoping someone can understand. The expression is all valid but when I go to calculate it, the output is 0 (however there should be some values because there are features that meet this criteria).

Code:

var grid = FeatureSetByName($datastore,'HWA_GRIDS_TREATMENT_local',['MARK_X_DATE_ONLY','GRID_COUNT'],false);
var mcfc_grid = Filter(grid, "Team = 'MCFC'");

var filter_table = ISOYear($feature.Date_Only) + "-" + ISOMonth($feature.Date_Only) + "-" + Day($feature.Date_Only)

var mcfc_grid_dateonly = ISOYear("MARK_X_DATE_ONLY") + "-" + ISOMonth("MARK_X_DATE_ONLY") + "-" + Day("MARK_X_DATE_ONLY")
//var filter_expression_date = "TREAT_X_DATE_ONLY = filter_table"
var filtered_grid = filter(mcfc_grid,"@mcfc_grid_dateonly = @filter_table")

var trees =sum(filtered_grid, 'GRID_COUNT')
return trees

 

screenshot of the field calculator tool attached as well. 

 

 

0 Kudos
4 Replies
Robert_LeClair
Esri Notable Contributor

One idea to consider is there are new Field Data Types introduced at ArcGIS Pro 3.2 - one of which is DATE only.  You could create a new field using this new field type, calculate the new DATE field from the old date field, then use the code to filter out date information without worrying about the time component.

0 Kudos
RileyScanlan
New Contributor II

Thanks for your response! I did do that, but I notice if I double click the field in the attribute table, it shows a timestamp of 12:00. Not sure how to prevent that?

 

 Capture.PNGCapture2.PNG

0 Kudos
Robert_LeClair
Esri Notable Contributor

Yes.  So I believe you're not using the correct field type.  In the Fields Designer, you need to select the "Date Only" field type rather than the "Date" field type.  I was able to replicate the behavior you're seeing using the Date field type.  If I use the "Date Only" field type, then I do not get the 12:00 AM timestamp.

RileyScanlan
New Contributor II

Okay yes was able to create a new Date Only field and transfer the info over, thank you! Though I am creating a local version of the grid layer because it is a hosted feature class used in several field maps. In the past I've had issues adding fields to a hosted layer from ArcGIS Pro.