<?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 Type of a DATE field changes to number after query in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302366#M81493</link>
    <description>&lt;P&gt;I have feature layer with a date field.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I check the fields before the query the field "&lt;SPAN&gt;last_edit" was "&lt;I&gt;esriFieldTypeDate" - line 46&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LefterisKoumis_0-1687506716536.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/74015i9230796A1B35B90F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LefterisKoumis_0-1687506716536.png" alt="LefterisKoumis_0-1687506716536.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;I&gt;After the query I checked the field and it was a number. - line 57,&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LefterisKoumis_1-1687506798065.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/74016iDA26571BDCCB89B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LefterisKoumis_1-1687506798065.png" alt="LefterisKoumis_1-1687506798065.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How do I keep the same field type?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;ArcGIS JavaScript Tutorials: Add your own custom button&amp;lt;/title&amp;gt;
  &amp;lt;style&amp;gt;
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;
  
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.16/esri/themes/light/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.16/"&amp;gt;&amp;lt;/script&amp;gt;
  
  &amp;lt;script&amp;gt;  
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer"
    ], function(Map, MapView, FeatureLayer) {
      
       const layer = new FeatureLayer({
      url: "https://gis.cnra.ca.gov/arcgis/rest/services/Boundaries/CCED_AccessType/MapServer/0"
    });

      var map = new Map({
        basemap: "topo-vector",
        layers: [layer]
      });

      var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-120.679, 37.910],
        zoom: 7
      });        
      
       const btn =document.getElementById("test")      
          view.ui.add(btn, "top-right")      
         btn.addEventListener("click", querylayer);
      
      function querylayer(evt) {
       console.log(layer.fields) 

        let query = new Query();
        query.where = "1=1";
        query.outFields = ["*"];

        layer.queryFeatures(query).then(function (results) {
        console.log(results.features);
        results.features.forEach(element =&amp;gt; {
        console.log(element.attributes)
        Object.keys(element.attributes).forEach(key =&amp;gt; {
        console.log(key + "  " + typeof(element.attributes[key]));       
      });
    })
    // exportToShapefile(results.features);
    return;
  });

      }
    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt; 
   &amp;lt;button id="test"&amp;gt;Test&amp;lt;/button&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jun 2023 07:55:06 GMT</pubDate>
    <dc:creator>LefterisKoumis</dc:creator>
    <dc:date>2023-06-23T07:55:06Z</dc:date>
    <item>
      <title>Type of a DATE field changes to number after query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302366#M81493</link>
      <description>&lt;P&gt;I have feature layer with a date field.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I check the fields before the query the field "&lt;SPAN&gt;last_edit" was "&lt;I&gt;esriFieldTypeDate" - line 46&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LefterisKoumis_0-1687506716536.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/74015i9230796A1B35B90F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LefterisKoumis_0-1687506716536.png" alt="LefterisKoumis_0-1687506716536.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;I&gt;After the query I checked the field and it was a number. - line 57,&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LefterisKoumis_1-1687506798065.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/74016iDA26571BDCCB89B4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LefterisKoumis_1-1687506798065.png" alt="LefterisKoumis_1-1687506798065.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How do I keep the same field type?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;ArcGIS JavaScript Tutorials: Add your own custom button&amp;lt;/title&amp;gt;
  &amp;lt;style&amp;gt;
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;
  
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.16/esri/themes/light/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.16/"&amp;gt;&amp;lt;/script&amp;gt;
  
  &amp;lt;script&amp;gt;  
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer"
    ], function(Map, MapView, FeatureLayer) {
      
       const layer = new FeatureLayer({
      url: "https://gis.cnra.ca.gov/arcgis/rest/services/Boundaries/CCED_AccessType/MapServer/0"
    });

      var map = new Map({
        basemap: "topo-vector",
        layers: [layer]
      });

      var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-120.679, 37.910],
        zoom: 7
      });        
      
       const btn =document.getElementById("test")      
          view.ui.add(btn, "top-right")      
         btn.addEventListener("click", querylayer);
      
      function querylayer(evt) {
       console.log(layer.fields) 

        let query = new Query();
        query.where = "1=1";
        query.outFields = ["*"];

        layer.queryFeatures(query).then(function (results) {
        console.log(results.features);
        results.features.forEach(element =&amp;gt; {
        console.log(element.attributes)
        Object.keys(element.attributes).forEach(key =&amp;gt; {
        console.log(key + "  " + typeof(element.attributes[key]));       
      });
    })
    // exportToShapefile(results.features);
    return;
  });

      }
    });
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt; 
   &amp;lt;button id="test"&amp;gt;Test&amp;lt;/button&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 07:55:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302366#M81493</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2023-06-23T07:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Type of a DATE field changes to number after query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302457#M81495</link>
      <description>&lt;P&gt;This is the correct behavior.&amp;nbsp; Dates are returned as a number in unix time (milliseconds since 1/1/1970).&amp;nbsp; If you need to convert to a date, just do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;new Date(element.getAttribute('last_edit'))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also I tried putting that in Codepen and it was throwing an error that Query was not defined, since you are not requiring it.&amp;nbsp; One thing you can do instead of requiring Query is to create a query from the layer:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const query = layer.createQuery();
//instead of
let query = new Query();&lt;/LI-CODE&gt;&lt;P&gt;If you were to query using the REST API, you'll see you do get a number returned for the date field:&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.cnra.ca.gov/arcgis/rest/services/Boundaries/CCED_AccessType/MapServer/0/query?where=1=1&amp;amp;outFields=last_edit&amp;amp;returnGeometry=false&amp;amp;f=html" target="_blank" rel="noopener"&gt;https://gis.cnra.ca.gov/arcgis/rest/services/Boundaries/CCED_AccessType/MapServer/0/query?where=1=1&amp;amp;outFields=last_edit&amp;amp;returnGeometry=false&amp;amp;f=html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JustinGreco1_0-1687530777106.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/74041iE675C026F761F64B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JustinGreco1_0-1687530777106.png" alt="JustinGreco1_0-1687530777106.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 14:48:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302457#M81495</guid>
      <dc:creator>Justin_Greco</dc:creator>
      <dc:date>2023-06-23T14:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Type of a DATE field changes to number after query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302517#M81498</link>
      <description>&lt;P&gt;Thank you for the reply.&amp;nbsp; I provided the above example just to demo my issue. Yes, I can convert it back to the date field as you suggested. However my actual case is an app where the user selects&amp;nbsp; a layer from a dropdown. Then, I have to access the selected layer's REST service. In the REST service some of the fields are classified as DATE and some are others are numbers. So, if I loop through the fields of the selected layer, all the fields are returned as numbers and I wouldn't know which fields are actually dates and which are numbers. Is there a way to distinguish the fields which are dates and which are not? Some of the layers have a lot of fields with a variety of field types.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 16:18:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302517#M81498</guid>
      <dc:creator>LefterisKoumis</dc:creator>
      <dc:date>2023-06-23T16:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Type of a DATE field changes to number after query</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302539#M81500</link>
      <description>&lt;P&gt;You'd want to determine the field type from the fields property of the layer (line 46).&amp;nbsp; Your line 57 is just returning the object type of that attribute for the feature, which would be number since the value is in milliseconds.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 16:58:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/type-of-a-date-field-changes-to-number-after-query/m-p/1302539#M81500</guid>
      <dc:creator>Justin_Greco</dc:creator>
      <dc:date>2023-06-23T16:58:54Z</dc:date>
    </item>
  </channel>
</rss>

