Select to view content in your preferred language

feature setDefiniition expression for a date

836
2
Jump to solution
04-24-2014 08:20 AM
AndrewL
Frequent Contributor
Hi I am trying to set up my def expression to display only points within the last 90 days using a feature service from the NWS.

However, no points are being displayed when I know some points should be. If I change the def expression to another field ("injuries > 3"); that works. I am not sure if the date field is formatted correctly and I could not find any examples. Thank you!

stormdate ( type: esriFieldTypeDate , alias: stormdate , editable: true , nullable: true , length: 36 )

var feature = new esri.layers.FeatureLayer(layer.url, {    infoTemplate: infoTemplate,           mode: esri.layers.FeatureLayer.MODE_ONDEMAND,    outFields: ["stormdate", "surveydate", "injuries"]    });     var pastDate = new Date();    pastDate.setDate(pastDate.getDate()-90);                          feature.setDefinitionExpression("stormdate >  pastDate");
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Hi Andrew,

Try the following:

var pastDate = new Date();         pastDate.setDate(pastDate.getDate()-90); pastDate = pastDate.getMonth()+1 + "/" + pastDate.getDate() + "/" + pastDate.getYear();                 featureLayer.setDefinitionExpression("stormdate > date '" + pastDate + "'");

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Andrew,

Try the following:

var pastDate = new Date();         pastDate.setDate(pastDate.getDate()-90); pastDate = pastDate.getMonth()+1 + "/" + pastDate.getDate() + "/" + pastDate.getYear();                 featureLayer.setDefinitionExpression("stormdate > date '" + pastDate + "'");
0 Kudos
AndrewL
Frequent Contributor
Hi Jake,

Thank you for your response.

After doing alert(pastDate) it was telling me that the pastDate was 1/24/114.

I changed "getYear" to "getFullYear" and now it is working fine.

Thanks!
0 Kudos