[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Count Weekdays Between Two Days

Posted on 2004-09-01
Medium Priority
Last Modified: 2012-06-21
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
Question by:bgarland
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 24

Accepted Solution

HemanthaKumar earned 500 total points
ID: 11955656
Here is the code...http://js-x.com/javascript/?view=66


Author Comment

ID: 11955697
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.
LVL 14

Assisted Solution

ziffgone earned 500 total points
ID: 11956171
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.


Author Comment

ID: 11956806
I take it back - I can use a function.
LVL 14

Expert Comment

ID: 11958047
Then, actually, Hemanth's post seems like a better, less time consuming way to do it than what I was explaining.


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question