CFLib.org – Common Function Library Project

businessDaysBetween(date1, date2)

Last updated April 10, 2008

Version: 1 | Requires: ColdFusion 5 | Library: DateLib

 
Rated 0 time(s). Average Rating: 0

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:

view plain print about
<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:

view plain print about
<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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson