<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Add &amp;#39;n&amp;#39; number of days(excluding weekends and holidays) to a given date.</title><link>https://community.appian.com/discussions/f/general/21285/add-n-number-of-days-excluding-weekends-and-holidays-to-a-given-date</link><description>Hi Community, 
 
 How to add &amp;#39;n&amp;#39; number of days(excluding weekends and holidays) to a given date? We have defined holidays in Database. I know it is possible to define a Process Calendar with a list of non-working days and then use it in caladddays()</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Add 'n' number of days(excluding weekends and holidays) to a given date.</title><link>https://community.appian.com/thread/82989?ContentTypeID=1</link><pubDate>Fri, 25 Jun 2021 16:47:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8050384e-1bb9-44f3-ac01-f28dd8a0f126</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Yea, I have this setup as a recursive function in some areas where additional processing is required.&amp;nbsp; Generally, fn!workday() should cover it, but if we need to expand the logic, a starting example is:&lt;/p&gt;
&lt;p&gt;rule!chris_test_add_days():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;a!localVariables(
  local!dateStart: today(), /* replace with rule input if you do not always want to add from today */
  local!addDays: 20,
  local!holidays: a!queryEntity(
    entity: cons!CHRIS_TEST_DS_HOLIDAYS,
    fetchTotalCount: false,
    query: a!query(
      /* make sure you include enough range - get the same # of future holidays as days adding */
      pagingInfo: a!pagingInfo(1,local!addDays,a!sortInfo(field: &amp;quot;date&amp;quot;,ascending: true)),
      filter: a!queryFilter(
        field: &amp;quot;date&amp;quot;,
        operator: &amp;quot;&amp;gt;&amp;quot;,
        value: local!dateStart
      )
    )
  ).data,
  
  rule!chris_test_add_days_recur(
    date: local!dateStart,
    addDays: local!addDays,
    daysAdded: 0,
    holidays: property(local!holidays,&amp;quot;date&amp;quot;,{})
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;rule!chris_test_add_days_recur(date (Date), addDays (Integer), daysAdded (Integer), holidays (List of Date)):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;if(
  ri!daysAdded=ri!addDays,
  ri!date,
  a!localVariables(
    local!nextDay: todate(caladddays(ri!date,1)),
    rule!chris_test_add_days_recur(
      date: local!nextDay,
      addDays: ri!addDays,
      daysAdded: ri!daysAdded+if(
        contains(
          ri!holidays,
          local!nextDay
        ),
        0,
        1
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As always with recursive functions, make sure you save your edits prior to testing!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add 'n' number of days(excluding weekends and holidays) to a given date.</title><link>https://community.appian.com/thread/82988?ContentTypeID=1</link><pubDate>Fri, 25 Jun 2021 16:31:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a7d9dc8a-6e1c-4682-85db-777c31e97380</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;That should help you - my additional thought was, if you&amp;#39;re storing your holidays in your database (as opposed to going through the fairly cumbersome and not-very-flexible process of defining them manually within your Appian environment), a brute-force approach would probably be feasible too - i.e. loop over a date range (like with a!forEach) and check each date for its &amp;quot;day of week&amp;quot; as well as whether it&amp;#39;s in your holidays DB.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Add 'n' number of days(excluding weekends and holidays) to a given date.</title><link>https://community.appian.com/thread/82986?ContentTypeID=1</link><pubDate>Fri, 25 Jun 2021 16:02:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fbc40d33-8136-463b-b21b-c84482faca56</guid><dc:creator>Arun Theja Muthyalu</dc:creator><description>&lt;p&gt;Alright, I found&amp;nbsp;workday() function will help in this regard.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>