<?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: How to maintain date data in arcade expressions in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1300668#M7971</link>
    <description>&lt;P&gt;Yep, it worked, thank you!&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jun 2023 11:27:32 GMT</pubDate>
    <dc:creator>SayedWali</dc:creator>
    <dc:date>2023-06-19T11:27:32Z</dc:date>
    <item>
      <title>How to maintain date data in arcade expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1125749#M5483</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;allready some time ago I noticed that arcade wouldn't allow me to keep my exisiting date data after casting it into a dictionary. It was not possible to simply define the corresponding field in the dictionary as esriFieldTypeDate and then send my exisiting dates into that dictionary by using a for-loop.&lt;/P&gt;&lt;P&gt;As an example that didn't produce the desired results, but kept at least the existing date data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var dict = {
fields: [
{ name: 'start_time', type: 'esriFieldTypeString' },
{ name: 'BP2_compost_adoption_yn', type: 'esriFieldTypeString' },
],
geometryType: '',
features: [],
};

var index = 0;

for (var feature in fv) {
dict.features[index] = {
'attributes': {
'start_time': Text(feature['start_time']),
'BP2_compost_adoption_yn': Text(feature['BP2_compost_adoption_yn'])
}}
index++;} &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Casting the date data into a string had the crucial disadvantage of not being able to filter that data in the dashboards anymore.&lt;/P&gt;&lt;P&gt;Unfortunatly the &lt;A href="https://developers.arcgis.com/arcade/function-reference/date_functions/" target="_self"&gt;arcade documentation about dates&lt;/A&gt; didn't tell how to cast dates into UNIX epoch time, which is shown as one input for the date function, and seems to be the neccessary input for the esriFieldTypeDate in a dictionary.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 09:15:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1125749#M5483</guid>
      <dc:creator>Merlin</dc:creator>
      <dc:date>2021-12-14T09:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to maintain date data in arcade expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1125750#M5484</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="2"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;P&gt;&lt;STRONG&gt;tl;dr:&lt;/STRONG&gt; use the &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#number" target="_self"&gt;number()&lt;/A&gt; function in the for-loop to cast existing date data into UNIX epoch time, this can be read by the esriFieldTypeDate as correct date.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By trial and error I ended up trying the &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#number" target="_self"&gt;number()&lt;/A&gt; function on a date, which produces the UNIX epoch time, which is further down the line accepted by the esriFieldTypeDate in a dictionary.&lt;/P&gt;&lt;P&gt;I guess if there would have been an example showing this capabillity of the number() function in the documentation I would have found this solution way faster (google doesnt bring up anything useful either).&lt;BR /&gt;Maybe this could be inculded &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1126"&gt;@DerekLaw&lt;/a&gt; ?&lt;/P&gt;&lt;P&gt;Well, here is an complete example of how to use the number() function in a way that keeps your exisiting date data alive:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var p = 'https://xxx';
var itemID = 'xxx';
var layerID = 0;

var fv = FeatureSetByPortalItem(Portal(p),itemID,layerID,
    ['start_time',
    'BP3_weed_adoption_yn'], 
    false );
    
var dict = {
  fields: [
    { name: 'start_time',           type: 'esriFieldTypeDate' },
    { name: 'BP3_weed_adoption_yn', type: 'esriFieldTypeString' },
  ],
  geometryType: '',
  features: [],
};

var index = 0; 

for (var feature in fv) { 
    dict.features[index] = { 
        'attributes': { 
           'start_time': Number(feature['start_time']), 
           'BP3_weed_adoption_yn': Text(feature['BP3_weed_adoption_yn'])
        }} 
    index++;} 
var fs_dict = FeatureSet(Text(dict));

return fs_dict&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 09:19:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1125750#M5484</guid>
      <dc:creator>Merlin</dc:creator>
      <dc:date>2021-12-14T09:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to maintain date data in arcade expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1130700#M5630</link>
      <description>&lt;P&gt;Good tip! Exactly what I was after.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 07:18:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1130700#M5630</guid>
      <dc:creator>SayedWali</dc:creator>
      <dc:date>2022-01-05T07:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to maintain date data in arcade expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1299930#M7955</link>
      <description>&lt;P&gt;With this week's update to Arcade and ArcGIS Dashboards, date fields in feature set constructors now just work. You no longer have to wrap dates with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Number()&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if you pass the &lt;EM&gt;dictionary&lt;/EM&gt; into the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;FeatureSet()&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;function (which as of this release accepts a dictionary as opposed to only text based JSON).&lt;/P&gt;&lt;P&gt;Instead of:&lt;/P&gt;&lt;PRE&gt;return FeatureSet(Text(dict))&lt;/PRE&gt;&lt;P&gt;Do this:&lt;/P&gt;&lt;PRE&gt;return FeatureSet(dict)&lt;/PRE&gt;&lt;P&gt;Learn more in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.esri.com/t5/arcgis-dashboards-blog/dashboard-data-expressions-what-has-changed-june/ba-p/1298782" target="_blank" rel="noopener"&gt;this blog post&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;NOTE: For Enterprise users, this update is targeted for 11.2&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 19:24:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1299930#M7955</guid>
      <dc:creator>DavidNyenhuis1</dc:creator>
      <dc:date>2023-06-15T19:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to maintain date data in arcade expressions</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1300668#M7971</link>
      <description>&lt;P&gt;Yep, it worked, thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 11:27:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/how-to-maintain-date-data-in-arcade-expressions/m-p/1300668#M7971</guid>
      <dc:creator>SayedWali</dc:creator>
      <dc:date>2023-06-19T11:27:32Z</dc:date>
    </item>
  </channel>
</rss>

