<?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 Calculating the difference between two date fields using arcade in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/calculating-the-difference-between-two-date-fields/m-p/1376090#M78080</link>
    <description>&lt;P&gt;I can't find the error in my code. I am trying to calculate the difference between the current date and a previous inspection date. I want the difference to be calculated in days. I am using ArcGIS Pro's field calculator for this task and am using Arcade code.&lt;/P&gt;&lt;P&gt;Field Calculator verifies the "Expression is valid" but when I run the code in Field Calculator for the 'Days_Since_Last_Inspection' field, the attribute table is not populated with any values and there are no errors... but the field still reads&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;lt;Null&amp;gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for each attribute in the 'Days_Since_Last_Inspection' field.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt; startDate=&lt;SPAN class=""&gt;Date&lt;/SPAN&gt;($feature.&lt;SPAN class=""&gt;Last_Inspection_Date&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;var&lt;/SPAN&gt; endDate=&lt;SPAN class=""&gt;Now&lt;/SPAN&gt;()
&lt;SPAN class=""&gt;var&lt;/SPAN&gt; result=&lt;SPAN class=""&gt;DateDiff&lt;/SPAN&gt;(endDate,startDate,&lt;SPAN class=""&gt;'days'&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;return&lt;/SPAN&gt; result&lt;/PRE&gt;&lt;P&gt;I have also tried adding a separate field to host todays date value. Therefore, the alternate code I have tried is:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt; startDate=&lt;SPAN class=""&gt;Date&lt;/SPAN&gt;($feature.&lt;SPAN class=""&gt;Last_Inspection_Date&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;var&lt;/SPAN&gt; endDate=&lt;SPAN class=""&gt;Date&lt;/SPAN&gt;($feature.&lt;SPAN class=""&gt;Today_Date&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;var&lt;/SPAN&gt; result=&lt;SPAN class=""&gt;DateDiff&lt;/SPAN&gt;(endDate,startDate,&lt;SPAN class=""&gt;'days'&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;return&lt;/SPAN&gt; result&lt;/PRE&gt;&lt;P&gt;And field calculator is still not producing a calculated result between the two dates.&lt;/P&gt;&lt;P&gt;I am using ArcGIS Pro version 2.9.5, the 'Last_Inspection_Date' field is a date field formatted as yyyy-M-d, and the 'Days_Since_Last_Inspection' field is formatted as numeric with a Short data type. I have tried creating a text field thinking it might be the data type of the field preventing the calculation but that has not worked either. I have tried the similar questions asked on the topic and can't figure out why the code runs but does not produce the desired output.&lt;/P&gt;&lt;P&gt;Additional Information: I populated the 'Last_Inspection_Date' field with random dates using the following arcade code:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;random_dates&lt;/SPAN&gt;(&lt;SPAN class=""&gt;"2010-1-1"&lt;/SPAN&gt;, &lt;SPAN class=""&gt;"2024-1-26"&lt;/SPAN&gt;)&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 19:57:21 GMT</pubDate>
    <dc:creator>JoshuaBarth</dc:creator>
    <dc:date>2024-01-30T19:57:21Z</dc:date>
    <item>
      <title>Calculating the difference between two date fields using arcade</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculating-the-difference-between-two-date-fields/m-p/1376090#M78080</link>
      <description>&lt;P&gt;I can't find the error in my code. I am trying to calculate the difference between the current date and a previous inspection date. I want the difference to be calculated in days. I am using ArcGIS Pro's field calculator for this task and am using Arcade code.&lt;/P&gt;&lt;P&gt;Field Calculator verifies the "Expression is valid" but when I run the code in Field Calculator for the 'Days_Since_Last_Inspection' field, the attribute table is not populated with any values and there are no errors... but the field still reads&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;lt;Null&amp;gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for each attribute in the 'Days_Since_Last_Inspection' field.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt; startDate=&lt;SPAN class=""&gt;Date&lt;/SPAN&gt;($feature.&lt;SPAN class=""&gt;Last_Inspection_Date&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;var&lt;/SPAN&gt; endDate=&lt;SPAN class=""&gt;Now&lt;/SPAN&gt;()
&lt;SPAN class=""&gt;var&lt;/SPAN&gt; result=&lt;SPAN class=""&gt;DateDiff&lt;/SPAN&gt;(endDate,startDate,&lt;SPAN class=""&gt;'days'&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;return&lt;/SPAN&gt; result&lt;/PRE&gt;&lt;P&gt;I have also tried adding a separate field to host todays date value. Therefore, the alternate code I have tried is:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;var&lt;/SPAN&gt; startDate=&lt;SPAN class=""&gt;Date&lt;/SPAN&gt;($feature.&lt;SPAN class=""&gt;Last_Inspection_Date&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;var&lt;/SPAN&gt; endDate=&lt;SPAN class=""&gt;Date&lt;/SPAN&gt;($feature.&lt;SPAN class=""&gt;Today_Date&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;var&lt;/SPAN&gt; result=&lt;SPAN class=""&gt;DateDiff&lt;/SPAN&gt;(endDate,startDate,&lt;SPAN class=""&gt;'days'&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;return&lt;/SPAN&gt; result&lt;/PRE&gt;&lt;P&gt;And field calculator is still not producing a calculated result between the two dates.&lt;/P&gt;&lt;P&gt;I am using ArcGIS Pro version 2.9.5, the 'Last_Inspection_Date' field is a date field formatted as yyyy-M-d, and the 'Days_Since_Last_Inspection' field is formatted as numeric with a Short data type. I have tried creating a text field thinking it might be the data type of the field preventing the calculation but that has not worked either. I have tried the similar questions asked on the topic and can't figure out why the code runs but does not produce the desired output.&lt;/P&gt;&lt;P&gt;Additional Information: I populated the 'Last_Inspection_Date' field with random dates using the following arcade code:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;random_dates&lt;/SPAN&gt;(&lt;SPAN class=""&gt;"2010-1-1"&lt;/SPAN&gt;, &lt;SPAN class=""&gt;"2024-1-26"&lt;/SPAN&gt;)&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 19:57:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculating-the-difference-between-two-date-fields/m-p/1376090#M78080</guid>
      <dc:creator>JoshuaBarth</dc:creator>
      <dc:date>2024-01-30T19:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the difference between two date fields using arcade</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculating-the-difference-between-two-date-fields/m-p/1376092#M78081</link>
      <description>&lt;P&gt;See my comment question over at &lt;A href="https://gis.stackexchange.com/questions/475087/calculate-date-difference-between-current-date-and-previous-date-using-arcade-wi?noredirect=1#comment775984_475087" target="_self"&gt;field calculator - Calculate date difference between current date and previous date using Arcade with ArcGIS Pro - GIS SE&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 19:59:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculating-the-difference-between-two-date-fields/m-p/1376092#M78081</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-01-30T19:59:45Z</dc:date>
    </item>
  </channel>
</rss>

