<?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 Exclude overnight hours in DateDiff calculation in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388089#M79458</link>
    <description>&lt;P&gt;I've written an Arcade attribute rule to calculate hours spent working on a project. I need to update that script to exclude the hours between 4:01PM and 6:59AM. My code is as follows:&lt;/P&gt;&lt;P&gt;var StartDate = $feature.TimeStart&lt;BR /&gt;var EndDate = $feature.TimeEnd&lt;BR /&gt;var TimeDiff = DateDiff(EndDate, StartDate, 'hours')&lt;BR /&gt;return TimeDiff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Link to previous post:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/update-integer-field-with-datediff/td-p/1388053#M79457" target="_blank"&gt;https://community.esri.com/t5/arcgis-pro-questions/update-integer-field-with-datediff/td-p/1388053#M79457&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2024 15:25:53 GMT</pubDate>
    <dc:creator>MikhaylaB</dc:creator>
    <dc:date>2024-02-28T15:25:53Z</dc:date>
    <item>
      <title>Exclude overnight hours in DateDiff calculation</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388089#M79458</link>
      <description>&lt;P&gt;I've written an Arcade attribute rule to calculate hours spent working on a project. I need to update that script to exclude the hours between 4:01PM and 6:59AM. My code is as follows:&lt;/P&gt;&lt;P&gt;var StartDate = $feature.TimeStart&lt;BR /&gt;var EndDate = $feature.TimeEnd&lt;BR /&gt;var TimeDiff = DateDiff(EndDate, StartDate, 'hours')&lt;BR /&gt;return TimeDiff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Link to previous post:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/update-integer-field-with-datediff/td-p/1388053#M79457" target="_blank"&gt;https://community.esri.com/t5/arcgis-pro-questions/update-integer-field-with-datediff/td-p/1388053#M79457&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 15:25:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388089#M79458</guid>
      <dc:creator>MikhaylaB</dc:creator>
      <dc:date>2024-02-28T15:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude overnight hours in DateDiff calculation</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388154#M79470</link>
      <description>&lt;P&gt;This should work. It calculates the number of days between the start date and end date and subtracts 15 hours for each day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var StartDate = $feature.TimeStart
var EndDate = $feature.TimeEnd
var TimeDiff = DateDiff(EndDate, StartDate, 'hours')
var DayDiff = DateDiff(DateOnly(EndDate), DateOnly((StartDate)), 'days')
var HoursOff = 15 * DayDiff

return TimeDiff - HoursOff&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 17:32:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388154#M79470</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-02-28T17:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude overnight hours in DateDiff calculation</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388196#M79474</link>
      <description>&lt;P&gt;Thanks, that should be good. Might you know how to include hours and minutes, like 2.5 hours? I noticed it rounds down to the closest hour.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 18:17:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388196#M79474</guid>
      <dc:creator>MikhaylaB</dc:creator>
      <dc:date>2024-02-28T18:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude overnight hours in DateDiff calculation</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388217#M79479</link>
      <description>&lt;P&gt;If you want the hours just rounded to something like 2.5, use&lt;A href="https://developers.arcgis.com/arcade/function-reference/math_functions/#round" target="_self"&gt; Round&lt;/A&gt; function (and &lt;A href="https://developers.arcgis.com/arcade/guide/template-literals/" target="_self"&gt;template literals&lt;/A&gt;)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return `${Round(TimeDiff - HoursOff, 1)} hours`&lt;/LI-CODE&gt;&lt;P&gt;You can add this to return the hours and minutes&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var TotalTime = TimeDiff - HoursOff
var Hours = Floor(TotalTime);
var Minutes = Floor((TotalTime - Hours) * 60)
return `${Hours} hours and ${Minutes} minutes`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 18:52:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1388217#M79479</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-02-28T18:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude overnight hours in DateDiff calculation</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1390290#M79701</link>
      <description>&lt;P&gt;I ultimately didn't need to exclude the overnight hours because I learned the work stops by end of business hours and a new entry is created for the next day. I did have an issue with my field not allowing decimals as a result from my equation, so I changed from a short integer to a double. I wanted hour and fraction of an hour as a whole number + decimal. Final code below:&lt;/P&gt;&lt;P&gt;var StartDate = $feature.TimeStart&lt;BR /&gt;var EndDate = $feature.TimeEnd&lt;BR /&gt;var TimeDiff = DateDiff(EndDate, StartDate, 'hours')&lt;BR /&gt;var Minutes = DateDiff(EndDate, StartDate, 'minutes')&lt;BR /&gt;var MinDiff = (Minutes-60)/60&lt;BR /&gt;var HourMin= Number(TimeDiff + MinDiff)&lt;BR /&gt;return TimeDiff&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 12:11:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1390290#M79701</guid>
      <dc:creator>MikhaylaB</dc:creator>
      <dc:date>2024-03-04T12:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude overnight hours in DateDiff calculation</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1399058#M80747</link>
      <description>&lt;P&gt;Hi, I have a question unrelated to this post, but you were very helpful with my last Arcade question. I have two attribute rules that I need to combine, because they are firing in the wrong order as separate rules. I need to first calculate the GPM from a value entered into the Flow field (both are fields in the same related table). I need that GPM value to update a parent feature class in the "class" field. Do you have an idea how I could combine these two expressions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Calculate GPM&lt;/P&gt;&lt;P&gt;var flow = $feature["Flow"];&lt;BR /&gt;var gpm = 0;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if (!isEmpty(flow)) {&lt;BR /&gt;gpm = (29.7 * (2.5 * 2.5) * Sqrt(flow) * 0.9)&lt;BR /&gt;}&lt;BR /&gt;return gpm;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Update Parent Class&lt;/P&gt;&lt;P&gt;var parent_id = $feature.hydrantObjid ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var parent_class = FeatureSetByName($datastore, "hydrantCopy", ["OBJECTID", 'class'], false);&lt;BR /&gt;var parent_records = Filter(parent_class, "OBJECTID = @parent_id");&lt;/P&gt;&lt;P&gt;var updates = [];&lt;BR /&gt;var i = 0;&lt;BR /&gt;var new_value = 'no gpm';&lt;/P&gt;&lt;P&gt;if ($feature.GPM &amp;gt;= 1500) {&lt;BR /&gt;new_value = "Blue - 1500 GPM or Greater";&lt;BR /&gt;}&lt;BR /&gt;else if ($feature.GPM &amp;gt;= 1000) {&lt;BR /&gt;new_value = "Green - 1000-1499 GPM";&lt;BR /&gt;}&lt;BR /&gt;else if ($feature.GPM &amp;gt;= 500){&lt;BR /&gt;new_value = "Orange - 500-999 GPM";&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;new_value = "Red - 0-499 GPM";&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for (var row in parent_records) {&lt;BR /&gt;// If the parent row is null or has a different value, updated it&lt;BR /&gt;if (IsEmpty(row['class']) || row['class'] != new_value)&lt;BR /&gt;{&lt;BR /&gt;updates[i++] = {&lt;BR /&gt;'OBJECTID': parent_id,&lt;BR /&gt;'attributes': {"class": new_value}&lt;BR /&gt;};&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;return {&lt;BR /&gt;'result': parent_id,&lt;BR /&gt;'edit': [&lt;BR /&gt;{'className': 'hydrantCopy',&lt;BR /&gt;'updates': updates&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;};&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 15:27:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/exclude-overnight-hours-in-datediff-calculation/m-p/1399058#M80747</guid>
      <dc:creator>MikhaylaB</dc:creator>
      <dc:date>2024-03-21T15:27:55Z</dc:date>
    </item>
  </channel>
</rss>

