CFLib.org – Common Function Library Project

businessDaysBetween(date1, date2)

Last updated April 10, 2008
Download UDF

author

Harry Goldman                                     Harry Goldman

Version: 1 | Requires: ColdFusion 5 | 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:

<cfscript>
/**
* 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;
}
</cfscript>

Search CFLib.org


Latest Additions

Raymond Compton Raymond Compton added
structBlend
19 day(s) ago

Duncan Duncan added
IsZIPUK
19 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
26 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson