Skip to main content

How to format DateRangePicker results to query a Portal feature using a date field.

Comments

2 comments

  • Berend Veldkamp

    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
  • Permanently deleted user

    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.