<?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 calculates the number of weekdays (Monday to Friday) between two date columns (Start Date and End Date) in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844970#M101946</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Hello Community,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I want to&amp;nbsp;&lt;/STRONG&gt;create a column formula in &lt;STRONG&gt;JMP&lt;/STRONG&gt;&amp;nbsp;18 that calculates the &lt;STRONG&gt;number of weekdays (Monday to Friday)&lt;/STRONG&gt; between two date columns (&lt;STRONG&gt;Start Date&lt;/STRONG&gt; and &lt;STRONG&gt;End Date&lt;/STRONG&gt;). Weekends (Saturday and Sunday) should be excluded. The formula must be compatible with &lt;STRONG&gt;JMP's column formula editor&lt;/STRONG&gt; and should not produce any errors. I don't use JSL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your support.&lt;/P&gt;</description>
    <pubDate>Fri, 28 Feb 2025 13:27:58 GMT</pubDate>
    <dc:creator>Christina</dc:creator>
    <dc:date>2025-02-28T13:27:58Z</dc:date>
    <item>
      <title>calculates the number of weekdays (Monday to Friday) between two date columns (Start Date and End Date)</title>
      <link>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844970#M101946</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hello Community,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I want to&amp;nbsp;&lt;/STRONG&gt;create a column formula in &lt;STRONG&gt;JMP&lt;/STRONG&gt;&amp;nbsp;18 that calculates the &lt;STRONG&gt;number of weekdays (Monday to Friday)&lt;/STRONG&gt; between two date columns (&lt;STRONG&gt;Start Date&lt;/STRONG&gt; and &lt;STRONG&gt;End Date&lt;/STRONG&gt;). Weekends (Saturday and Sunday) should be excluded. The formula must be compatible with &lt;STRONG&gt;JMP's column formula editor&lt;/STRONG&gt; and should not produce any errors. I don't use JSL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your support.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 13:27:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844970#M101946</guid>
      <dc:creator>Christina</dc:creator>
      <dc:date>2025-02-28T13:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: calculates the number of weekdays (Monday to Friday) between two date columns (Start Date and End Date)</title>
      <link>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844980#M101947</link>
      <description>&lt;P&gt;Can you provide example table with an example column with correct results?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 13:50:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844980#M101947</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-28T13:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: calculates the number of weekdays (Monday to Friday) between two date columns (Start Date and End Date)</title>
      <link>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844981#M101948</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/23360"&gt;@Christina&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give this a try. Just make sure to change the column names at the bottom to the names you have in your data table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ben&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);
dt = Current Data Table();

//Wipe the old weekday count column if it exists from this script being ran
try(dt:Weekdays Count&amp;lt;&amp;lt;set selected;dt&amp;lt;&amp;lt;delete columns(););
// Add a new column to store the number of weekdays
dt &amp;lt;&amp;lt; New Column("Weekdays Count", Numeric, "Continuous");

// Define a function to calculate weekdays between two dates
calcWeekdays = Function({startDate, endDate},
    {default local = 1},
    weekdays = 0;
    startDate = Date MDY(Month(startDate), Day(startDate), Year(startDate));
    endDate = Date MDY(Month(endDate), Day(endDate), Year(endDate));
    for(i = startDate, i &amp;lt;= endDate, i++,
        if(Day Of Week(i) != 1 &amp;amp; Day Of Week(i) != 7, // Exclude Sundays (1) and Saturdays (7)
            weekdays++;
        );
    );
    weekdays;
);

// Apply the function to each row - Convert to days with 86400 - //MAKE SURE TO CHANGE THE COLUMN NAMES HERE TO THE CORRECT TYPE
For Each Row(
    :Weekdays Count = (calcWeekdays(:Start Date, :End Date)/86400);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 14:25:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844981#M101948</guid>
      <dc:creator>Ben_BarrIngh</dc:creator>
      <dc:date>2025-02-28T14:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: calculates the number of weekdays (Monday to Friday) between two date columns (Start Date and End Date)</title>
      <link>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844992#M101950</link>
      <description>&lt;P&gt;Here are few formulas (no idea about their performance). Some slight adjustments might have to be done depending on how you wish to calculate the difference between two dates&lt;/P&gt;
&lt;P&gt;Using Summation&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Summation(i = 0, Date Difference(:start, :end, "day"),
	!(Day of week(:start + In Days(i)) == 7 | Day of week(:start + In Days(i)) == 1);
)&lt;/CODE&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using matrix + sum&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Sum(1 &amp;lt; Day of week(:start + (0::Date Difference(:start, :end, "day")) * In Days(1)) &amp;lt; 7)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example script&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(365),
	Compress File When Saved(1),
	New Column("start", Numeric, "Continuous", Format("d/m/y", 10), Input Format("d/m/y"), Formula(24Feb2025)),
	New Column("end", Numeric, "Continuous", Format("d/m/y", 10), Input Format("d/m/y"), Formula(24Feb2025 + In Days(Row() - 1))),
	New Column("Column 3",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Formula(
		Summation(i = 0, Date Difference(:start, :end, "day"),
			!(Day of week(:start + In Days(i)) == 7 | Day of week(:start + In Days(i)) == 1);
		)
		)
	),
	New Column("Column 3",
		Numeric,
		"Continuous",
		Format("Best", 12),
		Formula(
			Sum(1 &amp;lt; Day of week(:start + (0::Date Difference(:start, :end, "day")) * In Days(1)) &amp;lt; 7);
		)
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 14:37:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/844992#M101950</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-28T14:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: calculates the number of weekdays (Monday to Friday) between two date columns (Start Date and End Date)</title>
      <link>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/845441#M101996</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;thank you for the quick reply! With my data, both above mentioned formulas give the same result. I provide some example data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example: end date is 31.01.2025, start date is 23.01.2025. The result of both formulas is 7.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That are 7 working days, so thank you also for correct solutions :)&lt;/img&gt; ChatGPT wasn't able to solve that&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 17:11:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/calculates-the-number-of-weekdays-Monday-to-Friday-between-two/m-p/845441#M101996</guid>
      <dc:creator>Christina</dc:creator>
      <dc:date>2025-03-03T17:11:15Z</dc:date>
    </item>
  </channel>
</rss>

