CFLib.org – Common Function Library Project

BusinessDaysAdd(date, number)

Last updated August 10, 2005

author

Billy Cravens

Version: 2 | Requires: CF5 | Library: DateLib

Description:
Allows you to only add business days to a date (in other words, it ignores weekends). Unlike dateAdd(), it only works with days.

Return Values:
Returns a date object.

Example:

<cfoutput>
Start date: #DateFormat(Now(), 'dddd mmmm dd, yyyy')#<br>
Minus 10 business days: #DateFormat(BusinessDaysAdd(Now(), -10), 'dddd mmmm dd, yyyy')#<br>
Minus 5 business days: #DateFormat(BusinessDaysAdd(Now(), -5), 'dddd mmmm dd, yyyy')#<br>
Minus 3 business days: #DateFormat(BusinessDaysAdd(Now(), -3), 'dddd mmmm dd, yyyy')#<br>
Minus 2 business days: #DateFormat(BusinessDaysAdd(Now(), -2), 'dddd mmmm dd, yyyy')#<br>
Minus 1 business day : #DateFormat(BusinessDaysAdd(Now(), -1), 'dddd mmmm dd, yyyy')#<br>
Plus 1 business day : #DateFormat(BusinessDaysAdd(Now(), 1), 'dddd mmmm dd, yyyy')#<br>
Plus 2 business days: #DateFormat(BusinessDaysAdd(Now(), 2), 'dddd mmmm dd, yyyy')#<br>
Plus 3 business days: #DateFormat(BusinessDaysAdd(Now(), 3), 'dddd mmmm dd, yyyy')#<br>
Plus 5 business days: #DateFormat(BusinessDaysAdd(Now(), 5), 'dddd mmmm dd, yyyy')#<br>
Plus 10 business days: #DateFormat(BusinessDaysAdd(Now(), 10), 'dddd mmmm dd, yyyy')#<br>
</cfoutput>

Parameters:

Name Description Required
date Date you want to add business days to. Yes
number Number of business days to add to date. Yes

Full UDF Source:

/**
 * Works just like dateAdd(), except it only adds business days
 * Version 2 by Steven Van Gemert, svg2@placs.net
 * 
 * @param date      Date you want to add business days to. (Required)
 * @param number      Number of business days to add to date. (Required)
 * @return Returns a date object. 
 * @author Billy Cravens (billy@architechx.com) 
 * @version 2, August 10, 2005 
 */
function businessDaysAdd(date,number) {
  var cAdded = 0;
  var tempDate = date;
  var direction = compare(number,0);
  while (cAdded LT abs(number)) {
    tempDate = dateAdd("d",direction,tempDate);
    if (dayOfWeek(tempDate) GTE 2 AND dayOfWeek(tempDate) LTE 6) {
      cAdded = incrementValue(cAdded);
    }
  }
  return tempDate;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson