Count Weekdays Between Two Days

I need to place this in a calculated table column of a Brio file (which fully supports Javascript), so I can't use a function. But maybe a Do/While loop would work.

I have a column with an order date, a column with a shipment date and a column that calculates the number of days between the two dates. Now I need a new column that calculates only the number of business days (M-F) between those two dates. For example.

6/2/2004              6/14/2004                12                             8
6/25/2004            6/29/2004                4                               2
7/3/2004              7/4/2004                 1                               0
Who is Participating?
HemanthaKumarConnect With a Mentor Commented:
Here is the code...

bgarlandAuthor Commented:
Thanks Hemanth, I found that earlier. It's in the form of a function and I don't think that will work in my application.
ziffgoneConnect With a Mentor Commented:
That is an EXTREMELY difficult question, as you would have to preset a calendar to go off of. In order to figure out the week days, you would have to set up an array to compare with, containing all of the day names of the month.

var Sept = new Array('Wednesday','Thursday','Friday','Saturday','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday', ~ repeat all the way on through all days of the month to ,'Thursday');

In the array above, the first day would have to be the day that "01" resides on. For example, the array above is for this month, Sept. 01 is Wednesday, so the array starts with that. It would end with Thursday as Sept 30 falls on a Thurs. To make it simpler, you could abbreviate the names, "Sat" instead of "Saturday". You would have to set up an array for each month you'd want to check. So if you have a 12 month period to check, you would have to set up 12 arrays. I imagine, with a bit of calculating, you could dynamically set up a single array based upon the month number by pushing and delete array values. This way, the correct array would simply be created based upon the month number.

Then you would have to get the days from the Dates:

var arry;
var date = "6/2/2004";
var mon = date.split(/\//)[0];
if(mon == 1){
      arry = Jan;
if(mon == 2){
      arry = Feb;
etc... to our example and on to December:
if(mon == 9){
     arry = Sept;
var orderDate = "6/2/2004";
var orderDay = orderDate.split(/\//)[1];
var shipDate = "6/14/2004";
var shipDay = shipDate.split(/\//)[1];

And now check it against the array we defined by setting the correct Array needed to the "arry" value:

var wrkDays = 0;
var start = orderDay-1;
var end = shipDay-1;
      if((arry[i] != "Saturday") || (arry[i] != "Sunday")){

The value contained in "wrkDays" should now equal the number of week days within the stated time frame.

I imagine this could also be done with the Julian Calendar and a bunch of math, but that's another story.

Ultimately, I believe you may be hooped as you stated you coudn't use functions, and this would definitely need to be set up in a function.

bgarlandAuthor Commented:
I take it back - I can use a function.
Then, actually, Hemanth's post seems like a better, less time consuming way to do it than what I was explaining.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.