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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson