<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Featurelayer DefinitionExpression based on Date Range in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136338#M12660</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to define what current closure mean, today, this week or this month. and add between clause according.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 31 Aug 2015 17:27:05 GMT</pubDate>
    <dc:creator>thejuskambi</dc:creator>
    <dc:date>2015-08-31T17:27:05Z</dc:date>
    <item>
      <title>Featurelayer DefinitionExpression based on Date Range</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136337#M12659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a layer of construction closures in an app I'm developing and for each closure, there is a field for the starting date of the closure (startDate) and a field for the ending date of the closure (endDate). Ideally, I'd like to add a definitionExpression to the FeatureLayer to automatically handle the visibility of any current closures.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know I can't just use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var curDate = new Date();

var fLayer = new FeatureLayer("url", {
&amp;nbsp;&amp;nbsp;&amp;nbsp; definitionExpression:&amp;nbsp; "endDate &amp;lt;= Date " + curDate;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mode: FeatureLayer.MODE_ONDEMAND
});&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;because that would show current projects but also older, expired projects. So how would I structure the definition expression?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:35:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136337#M12659</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2021-12-11T07:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Featurelayer DefinitionExpression based on Date Range</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136338#M12660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to define what current closure mean, today, this week or this month. and add between clause according.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 17:27:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136338#M12660</guid>
      <dc:creator>thejuskambi</dc:creator>
      <dc:date>2015-08-31T17:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Featurelayer DefinitionExpression based on Date Range</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136339#M12661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's say I open the app today, which is August 31st. Given that, here are some scenarios:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLOSURE 1: startDate: August 1st, endDate: August 31st (closure should display)&lt;/P&gt;&lt;P&gt;CLOSURE 2: startDate: July 15th, endDate July 31st (closure should not display)&lt;/P&gt;&lt;P&gt;CLOSURE 3: startDate: August 25th, endDate: September 2nd (closure shoudld display)&lt;/P&gt;&lt;P&gt;CLOSURE 4: startDate: September 1st, endDate: September 2nd (closure should not display)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, as long as today's date lies between the startDate and endDate values, the closure should display.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 17:41:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136339#M12661</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2015-08-31T17:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Featurelayer DefinitionExpression based on Date Range</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136340#M12662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I dont understand what you are looking for. If getting the current date is the problem then below line should help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="kwd"&gt;var&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; today &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;new&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="typ"&gt;Date&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;();&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;var&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; dd &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; today&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;getDate&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;();&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;var&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; mm &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; today&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;getMonth&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;()+&lt;/SPAN&gt;&lt;SPAN class="lit"&gt;1&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;;&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; &lt;/SPAN&gt;&lt;SPAN class="com"&gt;//January is 0!&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="kwd"&gt;var&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; yyyy &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; today&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;getFullYear&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;();&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pln"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 17:56:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136340#M12662</guid>
      <dc:creator>thejuskambi</dc:creator>
      <dc:date>2015-08-31T17:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Featurelayer DefinitionExpression based on Date Range</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136341#M12663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This partially depends on how the data is stored in the service. For an &lt;EM style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14.3999996185303px;"&gt;esriFieldTypeDate. &lt;/EM&gt;We have used the following to some success, this was from a filter that said show everything in the last 48 hours.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14410489183127643 jive_text_macro" data-renderedposition="71_8_912_16" jivemacro_uid="_14410489183127643"&gt;&lt;P&gt;ACQ_DATE &amp;gt; date '2015-08-28 15:19:35'&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However since you want to show things in between two dates, you could use something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14410490296221313 jive_text_macro" data-renderedposition="150_8_912_16" jivemacro_uid="_14410490296221313" modifiedtitle="true"&gt;&lt;P&gt;startDate &amp;gt; date '2015-08-28 15:19:35' and endDate &amp;lt; date '2015-08-31 15:19:35';&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The date strings (eg. '2015-08-28 15:19:35') were formatted using JavaScripts Date class in my case, but they are getting sent in as strings so you can construct them in whatever manner is most appropriate for your application.&amp;nbsp; Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 19:26:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136341#M12663</guid>
      <dc:creator>RobertWinterbottom</dc:creator>
      <dc:date>2015-08-31T19:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Featurelayer DefinitionExpression based on Date Range</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136342#M12664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Robert. My date fields are defined as esriFieldTypeDate so your example should work with my situation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Sep 2015 19:58:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136342#M12664</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2015-09-01T19:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Featurelayer DefinitionExpression based on Date Range</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136343#M12665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to wrap a bow on this thread, I used Robert's suggestion but had to switch the less than/greater than signs to get it to work properly:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var today = new Date();
&amp;nbsp;&amp;nbsp;&amp;nbsp; var theDefExp = "startDate &amp;lt; date'" + today.toLocaleDateString() + "' and endDate &amp;gt; date '" + today.toLocaleDateString() + "'";
&amp;nbsp;&amp;nbsp;&amp;nbsp; constructionPtLayer.setDefinitionExpression(theDefExp);&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:35:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/featurelayer-definitionexpression-based-on-date/m-p/136343#M12665</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2021-12-11T07:35:33Z</dc:date>
    </item>
  </channel>
</rss>

