<?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 Re: How to calculate number of working days? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/305189#M56127</link>
    <description>&lt;P&gt;working with coding is new to me and i don't seem to get it to work. however i have played around with some of the standard formulas and found a solutions. that however use calendar days and not working days only. For this experiment it is good enough as along as it is the same for comparison.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Sep 2020 13:34:50 GMT</pubDate>
    <dc:creator>Martinej</dc:creator>
    <dc:date>2020-09-11T13:34:50Z</dc:date>
    <item>
      <title>How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/301956#M55960</link>
      <description>&lt;P&gt;Hi community&lt;/P&gt;&lt;P&gt;I need your help and advise once again. As a new user I'm struggling to learn.&lt;/P&gt;&lt;P&gt;I have a data table with start date and end date. I would like to calculate the number of working days in between the start and end date ?? How is the best way to do that in JMP ?? My idea is to add a column and make a formula, e.g. Date difference?? But i'm not sure what would be the better option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please see attached example&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Martinej_0-1599484248647.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/26636iA2A00F91704E5AD2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Martinej_0-1599484248647.png" alt="Martinej_0-1599484248647.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:18:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/301956#M55960</guid>
      <dc:creator>Martinej</dc:creator>
      <dc:date>2023-06-10T23:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/302014#M55963</link>
      <description>&lt;P&gt;The first thing you need to do is define "working day." Is it every weekday (Mon-Fri)? What about bank/government holidays? Religious holidays?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 14:11:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/302014#M55963</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2020-09-07T14:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/302103#M55971</link>
      <description>&lt;P&gt;Other questions too: JMP dates always include a time, often set to zero seconds after midnight. But if the range is noon Monday to noon Monday 7 days later, how do you want to count the two half-Mondays? Or even if it is midnight at the start of Monday, should both be counted?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Counting the days might not be a bad choice if your ranges are small and not too many (poorly tested code follows):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// define an expression that answers the question
includeThisDate = Expr(
	2/*monday*/&amp;lt;= Day Of Week( date ) &amp;lt;= 6/*friday*/
);

// brute force counting:
countSelectedDaysInRange = Function( {firstDate, lastDate, testexpr},
	{date, count},
	If( lastDate &amp;lt; firstDate,
		Throw( "dates reversed" )
	);
	count = 0;
	For( date = firstDate, date &amp;lt;= lastDate, date += In Days( 1 ),
		count += (testexpr != 0)
	);
	count;
);

Show( 262 == countSelectedDaysInRange( 1jan2020, 31dec2020, Name Expr( includeThisDate ) ) );
Show( 104 == countSelectedDaysInRange( 1jan2020, 31dec2020, Expr( !(2/*monday*/&amp;lt;= Day Of Week( date ) &amp;lt;= 6/*friday*/) ) ) );
Show( 366 == countSelectedDaysInRange( 1jan2020, 31dec2020, 1 ) );// 2020 is leap year
Show( 0 == countSelectedDaysInRange( 1jan2020, 31dec2020, 0 ) );// no days counted&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;262 == countSelectedDaysInRange(01Jan2020, 31Dec2020, Name Expr(includeThisDate)) = 1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;104 == countSelectedDaysInRange(01Jan2020, 31Dec2020, Expr(!(2 &amp;lt;= Day Of Week(date) &amp;lt;= 6))) = 1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;366 == countSelectedDaysInRange(01Jan2020, 31Dec2020, 1) = 1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;0 == countSelectedDaysInRange(01Jan2020, 31Dec2020, 0) = 1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code above includes the last day (&amp;lt;= lastdate rather than &amp;lt;lastdate) . It starts at the first datetime value and increments by 24 hours and adds one to the count if that datetime value satisfies the expression.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From painful experience I know working with dates and times is hard to get right.&lt;/P&gt;&lt;P&gt;Use the builtin functions as much as possible.&lt;/P&gt;&lt;P&gt;Comment the code for whoever maintains it next.&lt;/P&gt;&lt;P&gt;Test your code carefully!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, if you only need a crude approximation,&lt;/P&gt;&lt;P&gt;(1jan2021-1jan2020)/indays(1)*5/7 == 261.428571428571&lt;/P&gt;&lt;P&gt;which is close to the 262 count.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit:&amp;nbsp;&lt;EM&gt;date difference(1jan2020,1jan2021,"day")*5/7&lt;/EM&gt; might look simpler for the crude answer&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 22:40:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/302103#M55971</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-09-07T22:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/303333#M56020</link>
      <description>&lt;P&gt;yes working days is every weekday, (mon-fri) it would be best if i can also adjust for local holidays&lt;/P&gt;&lt;P&gt;any suggestions?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 08:34:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/303333#M56020</guid>
      <dc:creator>Martinej</dc:creator>
      <dc:date>2020-09-09T08:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/303551#M56032</link>
      <description>&lt;P&gt;The simple solution would be to extend the test expression.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// define an expression that answers the question

holidays = associativearray({1jan2020,25dec2020});

includeThisDate = Expr(
	(2/*monday*/&amp;lt;= Day Of Week( date ) &amp;lt;= 6/*friday*/) 
	&amp;amp;
	!(holidays&amp;lt;&amp;lt;contains(date-timeofday(date)))
);

// brute force counting:
countSelectedDaysInRange = Function( {firstDate, lastDate, testexpr},
	{date, count},
	If( lastDate &amp;lt; firstDate,
		Throw( "dates reversed" )
	);
	count = 0;
	For( date = firstDate, date &amp;lt;= lastDate, date += In Days( 1 ),
		count += (testexpr != 0)
	);
	count;
);

Show( 260 == countSelectedDaysInRange( 1jan2020, 31dec2020, Name Expr( includeThisDate ) ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;New Years and Christmas fall on weekdays in 2020, so 260 rather than 262. You'll need to update the associative array sometime in the future, and you might need historical data as well. Some holidays don't fall on the same day every year. What an ugly problem, which leads to...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A complicated solution might use something like&amp;nbsp;&lt;A href="https://www.abstractapi.com/holidays-api" target="_self"&gt;https://www.abstractapi.com/holidays-api&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Credit to&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6878"&gt;@Jeff_Perkinson&lt;/a&gt;&amp;nbsp; for&amp;nbsp;&lt;LI-MESSAGE title="Changing a date and time column to yield only the date." uid="53625" url="https://community.jmp.com/t5/Discussions/Changing-a-date-and-time-column-to-yield-only-the-date/m-p/53625#U53625" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;)&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 14:30:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/303551#M56032</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-09-09T14:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/305189#M56127</link>
      <description>&lt;P&gt;working with coding is new to me and i don't seem to get it to work. however i have played around with some of the standard formulas and found a solutions. that however use calendar days and not working days only. For this experiment it is good enough as along as it is the same for comparison.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 13:34:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/305189#M56127</guid>
      <dc:creator>Martinej</dc:creator>
      <dc:date>2020-09-11T13:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/305690#M56154</link>
      <description>&lt;P&gt;To add a bit to&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;'s and&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6878"&gt;@Jeff_Perkinson&lt;/a&gt;'s thoughts around holidays etc., you mentioned thoughts around accounting for 'local holidays'. That gets really difficult unless you adopt some standard definition for 'local'. For example, Canada has a 'Thanksgiving' holiday, just like the US. Except it's a different day on the calendar for Canada compared to the US. And don't even get me started at a city or state level in the US. For example, in the states of Maine and Massachusetts, Patriot's Day is a holiday, not celebrated anywhere else in the US. To make it even more sticky, some businesses close...others remain open. Banks and financial institutions included.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 17:20:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/305690#M56154</guid>
      <dc:creator>P_Bartell</dc:creator>
      <dc:date>2020-09-12T17:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/305691#M56155</link>
      <description>&lt;P&gt;My favorite is the old North Carolina &lt;A href="https://www.ncpedia.org/easter-monday-holiday" target="_blank" rel="noopener"&gt;baseball holiday&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2020 17:34:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/305691#M56155</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-09-12T17:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/306110#M56171</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/19234"&gt;@Martinej&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I wrote an add-in awhile back that calculates the number of working days between two date columns. Holidays and any other specific days you want to exclude are addressed by maintaining a Holiday List.jmp file stored in your add-in directory. Note: this file could be any document (Excel, .txt, .csv, etc) maintained in any location accessible by the JMP user's machine, however, this would require a minor tweak to the underlying JSL to provide the file location. Otherwise, I believe it addresses your requested need as-is. Follow the instructions for downloading, installing, and editing the Holiday List file:&lt;LI-MESSAGE title="NETWORKDAYS Function" uid="38321" url="https://community.jmp.com/t5/JMP-Add-Ins/NETWORKDAYS-Function/m-p/38321#U38321" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Jerry&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2020 12:58:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/306110#M56171</guid>
      <dc:creator>jerry_cooper</dc:creator>
      <dc:date>2020-09-14T12:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate number of working days?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/308546#M56284</link>
      <description>&lt;P&gt;Hi Jerry&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this was really helpfull. I made my own list and now it showed what i would like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 14:06:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-calculate-number-of-working-days/m-p/308546#M56284</guid>
      <dc:creator>Martinej</dc:creator>
      <dc:date>2020-09-17T14:06:42Z</dc:date>
    </item>
  </channel>
</rss>

