<?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 How to exclude weekends and holidays with function DateDiff? in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343280#M55422</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need to create an indicator in Dashboard that displays the number of remaining days between a start date and the end date, that also excludes weekends and holidays in the calculation.&lt;/P&gt;&lt;P&gt;I saw this script&lt;/P&gt;&lt;PRE&gt;var remaindays = DateDiff($feature.endDate&lt;SPAN&gt;, &lt;/SPAN&gt;Today()&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'days'&lt;/SPAN&gt;);&lt;BR /&gt;&lt;SPAN&gt;return &lt;/SPAN&gt;when (days&amp;gt;&lt;SPAN&gt;30&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"on schedule"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;             days&amp;gt;=&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"nearly due"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;             &lt;SPAN&gt;"overdue"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;P&gt;but I am struggling to find a way to add the exclusion. I believe that somehow I will need to add +1 or +2 whether there are a Saturday and/or a Sunday in between the 2 dates,&amp;nbsp; and a list of holidays, into the script.&lt;/P&gt;&lt;P&gt;Any help will be greatly appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Oct 2023 14:35:48 GMT</pubDate>
    <dc:creator>RudyJamet</dc:creator>
    <dc:date>2023-10-30T14:35:48Z</dc:date>
    <item>
      <title>How to exclude weekends and holidays with function DateDiff?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343280#M55422</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need to create an indicator in Dashboard that displays the number of remaining days between a start date and the end date, that also excludes weekends and holidays in the calculation.&lt;/P&gt;&lt;P&gt;I saw this script&lt;/P&gt;&lt;PRE&gt;var remaindays = DateDiff($feature.endDate&lt;SPAN&gt;, &lt;/SPAN&gt;Today()&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'days'&lt;/SPAN&gt;);&lt;BR /&gt;&lt;SPAN&gt;return &lt;/SPAN&gt;when (days&amp;gt;&lt;SPAN&gt;30&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"on schedule"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;             days&amp;gt;=&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"nearly due"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;             &lt;SPAN&gt;"overdue"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;P&gt;but I am struggling to find a way to add the exclusion. I believe that somehow I will need to add +1 or +2 whether there are a Saturday and/or a Sunday in between the 2 dates,&amp;nbsp; and a list of holidays, into the script.&lt;/P&gt;&lt;P&gt;Any help will be greatly appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 14:35:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343280#M55422</guid>
      <dc:creator>RudyJamet</dc:creator>
      <dc:date>2023-10-30T14:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude weekends and holidays with function DateDiff?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343349#M55429</link>
      <description>&lt;P&gt;Here's a similar post I wrote to remove weekends and holidays from a date span. Not exactly the same problem, but it's an idea.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129648/highlight/true#M5592" target="_blank"&gt;https://community.esri.com/t5/arcgis-dashboards-questions/arcade-return-a-date-in-the-future-not-including/m-p/1129648/highlight/true#M5592&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For your particular question, we're just trying to calculate how many workdays are between today and the end date, minus holidays and weekends. The weekends are easy enough.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// start and end dates
var edate = Date(2023, 10, 1)
var sdate = Now()

Console(sdate, 'to', edate)

// get total days between the two
var full_days = Ceil(DateDiff(edate, sdate, 'days'))

Console(full_days, 'full count of day span')

// get partial week gap
// positive value means we completed the week and have extra
// negative value means we didn't complete the week
var partial_gap = Weekday(edate) - Weekday(sdate)

Console(partial_gap, 'partial week days')

var weeks = Iif(
  partial_gap &amp;gt;= 0,
  (full_days - partial_gap) / 7,
  ((full_days - partial_gap) / 7) - 1
)

Console(weeks, 'weeks')

var workdays = full_days - (weeks * 2)

Console(workdays, 'workdays')

// handling the partial week, looking for other weekends
var extra_days = (7 + partial_gap) % 7

// if weekday = 0 or 6, it's a weekend
// adding the extra day value to our weekday means 6 == 1 more weekend, 7+ == 2 more
workdays = When(
  Weekday(sdate) + extra_days == 6, workdays - 1,
  Weekday(sdate) + extra_days &amp;gt; 6, workdays -2,
  workdays
)

return workdays&lt;/LI-CODE&gt;&lt;P&gt;You can see that other post for ideas about handling holidays, but this should get you a count of non-weekend days between two dates.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 16:04:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343349#M55429</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-10-30T16:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude weekends and holidays with function DateDiff?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343394#M55434</link>
      <description>&lt;P&gt;If someone comes across this and needs a python solution.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import numpy as np
from datetime import date
d1 = date(2023, 1, 1) 
d2 = date(2023, 12, 31)
days = np.busday_count(d1,d2, holidays = ["2023-01-01", "2023-07-01", "2023-12-24"])
print(days)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; You can produce a regions specific or user specific "holidays" list&lt;/P&gt;&lt;P&gt;Further info&lt;/P&gt;&lt;P&gt;&lt;A href="https://numpy.org/devdocs/reference/generated/numpy.busday_count.html" target="_self"&gt;Dates in NumPy — NumPy v2.0.dev0 Manual&lt;/A&gt;&lt;/P&gt;&lt;P&gt;There are other functions that may eventually make it to Arcade over time&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 16:41:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343394#M55434</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-10-30T16:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude weekends and holidays with function DateDiff?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343422#M55437</link>
      <description>&lt;P&gt;Thank you Josh, I will give it a try.&lt;/P&gt;&lt;P&gt;Rodolphe&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 17:13:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343422#M55437</guid>
      <dc:creator>RudyJamet</dc:creator>
      <dc:date>2023-10-30T17:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to exclude weekends and holidays with function DateDiff?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343424#M55438</link>
      <description>&lt;P&gt;Good to know, thanks Dan.&lt;/P&gt;&lt;P&gt;Rodolphe&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 17:13:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-exclude-weekends-and-holidays-with-function/m-p/1343424#M55438</guid>
      <dc:creator>RudyJamet</dc:creator>
      <dc:date>2023-10-30T17:13:55Z</dc:date>
    </item>
  </channel>
</rss>

