Solved

Count Weekdays Between Two Days

Posted on 2004-09-01
5
650 Views
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.

ORDER DATE        SHIPMENT DATE        DELTA IN DAYS          DELTA IN WORK DAYS
6/2/2004              6/14/2004                12                             8
6/25/2004            6/29/2004                4                               2
7/3/2004              7/4/2004                 1                               0
0
Comment
Question by:bgarland
[X]
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
5 Comments
 
LVL 24

Accepted Solution

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

~Hemanth
0
 

Author Comment

by:bgarland
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.
0
 
LVL 14

Assisted Solution

by:ziffgone
ziffgone earned 125 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.

EX:
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;
for(i=start;i==end;i++){
      if((arry[i] != "Saturday") || (arry[i] != "Sunday")){
            wrkDays++;
      }
}

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.

Regards...    
0
 

Author Comment

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

Expert Comment

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

Regards...
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

705 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