Select to view content in your preferred language

syntax to query a featureLayer using date field with Arcgis JS api?

4740
1
02-04-2015 07:48 AM
JohnSnow3
Deactivated User

i have a featureLayer in my JS map, (snapshot_mode), I can make queries on the layer as below (so my issue is specifically how query the layer based on a date field e.g. show all features newer than 01/01/2014) -

 featurelayer.setDefinitionExpression("status = 0"); // for example this is working

I have looked through the documentation, however no success... I am unable to query the layer based on a date field,
I have tried both a static ("date_created > 2014-01-01") as well as passing in a js date variable - "new date(...) and a couple of others,
I also saw there is a setTimeDefinition, which I also attempted to use, but still an unsuccessful outcome,


so, any advice on how to filter by date will be very much appreciated,

thanks!

0 Kudos
1 Reply
SteveCole
Honored Contributor

Dates values are in Epoch format so you'll need to specify your date value as such. If you have your date of interest as a variable, then the Epoch value of that date would be:

var epochDate = theDate.getTime() / 1000;

Your query then should be

"date_created > " + epochDate

This is untested, though..