How to format DateRangePicker results to query a Portal feature using a date field.
I am using the DateRangePicker to get a range of dates to query a basic feature service hosted on my agencies ArcGIS Portal. I am using the "Query Layer" activity to try and return the features that I want to use in my workflow. I can query the layer on the REST endpoint using this format: created_date < 'yyyy-MM-dd'
However, whenever I try to use $form1.state.dateRangePicker1.value.endDate, it returns dates in the wrong format. I've tried formatting the output using .format, ToString, .value, .display, and have got some different results that were closer, but there doesn't seem to be a consistent way to format the output of the form's dateRangePicker to the yyyy-mm-dd format. A lot of the methods that should work either return [Object object] or {local function}.
-
What have you tried? This seems to work for me:
=`MY_FIELD BETWEEN DATE '${ $form1.state.dateRangePicker1.value.startDate.getFullYear() }-${ $form1.state.dateRangePicker1.value.startDate.getMonth() + 1 }-${ $form1.state.dateRangePicker1.value.startDate.getDate() }' AND DATE '${ $form1.state.dateRangePicker1.value.endDate.getFullYear() }-${ $form1.state.dateRangePicker1.value.endDate.getMonth() + 1 }-${ $form1.state.dateRangePicker1.value.endDate.getDate() }'`Documentation for the date object is here. Note that getMonth() returns a value between 0 and 11, so you need to add 1.
ArcGIS stores dates in UTC by default, so depending on your requirements, you may have to account for the time difference in your region. For instance where I live, at 1:00 AM it will still be the previous day in UTC. If only using a date, I would be a full day off.
The above code might be simplified a bit by using $form1.state.dateRangePicker1.value.startDate.getISOString().substr(0,10), but this will be the UTC date, not the local date. The iso output of the Format Date activity basically does the same thing.
If you get [Object object] you probably forgot to call a specific method or property from that object, e.g. $form1.state.dateRangePicker1.value.startDate without getMonth()
If you get {local function} you probably forgot parentheses, e.g. getMonth without ()
1 -
The code you provided worked, I was using the autofill and didn't realize those functions required parenthesis. I had a similar codeblock to what you provided but kept getting the {local function} error. Thanks for the sanity check.
0
Please sign in to leave a comment.
Comments
2 comments