Thursday, October 13, 2011

Servoy TIP: Next Work Day Function

I needed a simple function that would return the next working day (Monday - Friday) from the date that was passed in. So here it is - it's simple, but it works:


function getNextWorkDay(myDate){

   var dow = myDate.getDay();
   var daysToAdd = 1;
   //remember JS days start at 0!
   if(dow >= 5 ) { daysToAdd = 8 - dow; }
   return new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate() + daysToAdd);

}

No comments:

Web Analytics