[GIS] Querying featureLayer using date field and ArcGIS API for JavaScript

arcgis-javascript-apidatefeature-layer

I can query a featureLayer in my javascript map to only show features meeting criteria for normal attributes (strings/integers), as below for example

featurelayer.setDefinitionExpression("status = 0"); // working fine

However i would like to query based on date field in my feature layer – (e.g. only display records newer than 01/01/2014)

in the service metadata the field is described as:

date_created ( type: esriFieldTypeDate , alias: DATE_CREATED , length: 36 )

I have looked through the the documentation, however i have seen no mention of how to do this kind of query, the closest thing mentioned is the setTimeDefinition, but this appears more related to making time-aware maps rather than performing a simple filter on a layer

Best Answer

You would set the expression as MYDATE >= date'1-16-2013' (date format may vary based on locale)

Example date range filter :

featurelayer.setDefinitionExpression("MYDATE >= date'1-16-2013' AND MYDATE < date'1/29/2015'")