CFLib.org – Common Function Library Project

businessDaysBetween(date1, date2)

Last updated April 10, 2008

author

Harry Goldman

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Calculates the number of business days between 2 dates. Holidays are not excluded. This count does not include the first day. So if you compare today (and today is Monday) to tomorrow, then your result is the difference (1).

Return Values:
Returns a number.

Example:

<cfoutput>
Number of work days between #DateFormat(CreateDate(2004,2,2),"dd-mmm-yyyy")# and #DateFormat(CreateDate(2004,2,10),"dd-mmm-yyyy")# is 
#businessDaysBetween(CreateDate(2004,2,2),CreateDate(2004,2,10))# day(s).
</cfoutput>

Parameters:

Name Description Required
date1 First date. Yes
date2 Second date. Yes

Full UDF Source:

/**
 * Calculates the number of business days between 2 dates.
 * 
 * @param date1      First date. (Required)
 * @param date2      Second date. (Required)
 * @return Returns a number. 
 * @author Harry Goldman (harry@icn.net) 
 * @version 1, April 10, 2008 
 */
function businessDaysBetween(date1,date2) {
    var numberOfDays = 0;
    
    while (date1 LT date2) {
        date1 = dateAdd("d",1,date1);
        if(dayOfWeek(date1) GTE 2 AND dayOfWeek(date1) LTE 6) numberOfDays = incrementValue(numberOfDays);
    }

    return numberOfDays;
}

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