After trying a few different ways, I finally sat down and just wrote out my own 
function to do what I wanted it to.  Below is my example code that works (as 
far as I know so far).  It takes the current date and adds a number of days to 
it (in this case, it is 10 days) and it only counts weekdays.  I didn't exclude 
holidays, but I assume this could be added in by using an array of dates that 
you must statically build.  Hope this helps someone from having to do as much 
searching as I did!

var dueDate = 10  //number of days to add
var daysToAdd = 0
var mydate = new Date()
document.write(mydate+"<br><br>")
var day = mydate.getDay()                       
dueDate = dueDate - (5-day) 
if ((5-day) < dueDate || dueDate == 1) {
  daysToAdd = (5-day) + 2 + daysToAdd
} else { // (5-day) >= dueDate
  daysToAdd = (5-day) + daysToAdd
}
while (dueDate != 0) {
  var week = dueDate - 5 
  if (week > 0) {
    daysToAdd = 7 + daysToAdd 
    dueDate = dueDate - 5 
  } else { // week < 0
    daysToAdd = (5 + week) + daysToAdd 
    dueDate = dueDate - (5 + week)
  }
}
mydate.setDate(mydate.getDate() + daysToAdd)
document.write(mydate)

                        
-Jon


> Hi, I have a funtion that adds a given amount of days (taken from the 
> user) and adds that to a date to get a new date.  I need to modify it 
> so that only weekdays are included when you add the days.  For example, 
> if you have today's date (9/26/06) and you want to add 5 days, the 
> answer should be 10/3/06 because the weekend should not be counted.  
> Does anyone know how this can be done?
> 
> var numberOfDaysToAdd = 5
> var mydate1 = new Date()  
> mydate1.setFullYear(2006,9,26)  
> mydate1.setDate(mydate1.getDate() + numberOfDaysToAdd) 
> 
> Any help would be appreciated, 
Thanks!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/Javascript/message.cfm/messageid:3233
Subscription: http://www.houseoffusion.com/groups/Javascript/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.33

Reply via email to