Arcade Filter by Date

5525
6
Jump to solution
05-06-2020 06:52 AM
KevinBrown10
New Contributor III

Hello, 

I wish to utilize the Filter function in Arcade to only return results between 1/1/2019 and 12/31/2019.  I understand the Filter function is  Filter(featurerSet, filter) where filter is an SQL text string.  The features are stored with a Date/Time field.  I am just not understanding the proper SQL commands for working with Date/Time. 

Any help or direction to more resources is appreciated.   

I tagged you Xander Bakker‌ because I (a non-programmer) have learned much about Arcade following your numerous examples and help to others on GeoNet. 

Thanks.

Kevin

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi k.brown ;

It seems that the expression below works (the same format as you would use in Desktop):

var sql = "LASTUPDATE BETWEEN date '01/01/2019' and date '12/31/2019'";
var fs = Filter($layer, sql);
return Count(fs);

View solution in original post

6 Replies
XanderBakker
Esri Esteemed Contributor

Hi k.brown ;

It seems that the expression below works (the same format as you would use in Desktop):

var sql = "LASTUPDATE BETWEEN date '01/01/2019' and date '12/31/2019'";
var fs = Filter($layer, sql);
return Count(fs);
KevinBrown10
New Contributor III

Perfect!  This worked for me.  

Thank you very much for your quick response.  As I stated, I do not have much coding experience but following along with your examples is very helpful.

Much appreciated.

KB

XanderBakker
Esri Esteemed Contributor

Hi https://community.esri.com/people/k.brown,

I'm glad it worked! 

0 Kudos
TL2
by
Occasional Contributor III

I am using this same filter() in Pro 3.0 with a service published to Server/Federated 10.9.1.  My arcade expression works fine in Pro, but it fails in Field Maps and Web AppBuilder with the error on the filter()  - Line 4: "Failed to query statistics".  Are there any limitations to this, I wouldn't think so.

 

My Holidays table is just a table of holidays, querying of the date column.

 

var t30 = dateadd($feature.initialreport,42,'days')
var t = dateadd($feature.initialreport,0,'days')
//query my date field - dt - on my holidays table
var sqls = "dt BETWEEN @t and @t30";
var fs = count(Filter(FeatureSetbyName($datastore, "SUDOECMS.DBO.Holiday"), sqls))
var dayz = dateadd($feature.initialreport,fs + 42,'days')
return dayz;

 

0 Kudos
nanayawosei
New Contributor

Hi 

I am trying to implement a similar query with arcade and sql, but I can not seem to get it to work when I include variables for my dates:

var myDate1  = '01/01/2019'

var myDate2  = '12/31/2019'

var sql = "LASTUPDATE BETWEEN date 'myDate1' and date 'MyDate2'";

var fs = Filter($layer, sql);

return Count(fs);‍‍‍

 

Thanks ,

Nana

0 Kudos
TomNeer
New Contributor III

 

Nana,

You probably figured this out but use the @ symbol in front of your variables to call them inline.

var sql = "LASTUPDATE BETWEEN @myDate1 and @MyDate2";