CFLib.org – Common Function Library Project

Weekdays(date1, date2)

Last updated October 9, 2001
Download UDF

author

Dan Anderson                                      Dan Anderson

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

 
Rated 0 time(s). Average Rating: 0

Description:
Returns the number of weekdays between two dates.

Return Values:
Returns a numeric value.

Example:

<CFSET date1="January 1, 2001">
<CFSET date2="12/31/01">
<CFOUTPUT>
Weekdays between #Date1# and #Date2# =
#weekdays("1/1/01","12/31/01")#
</CFOUTPUT>

Parameters:

Name Description Required
date1 Start date for the date range. Can take any valid CF date format. Yes
date2 End date for the date range. Can take any valid CF date format. Yes

Full UDF Source:

<cfscript>
/**
* Returns the number of weekdays between two dates.
*
* @param date1      Start date for the date range. Can take any valid CF date format.
* @param date2      End date for the date range. Can take any valid CF date format.
* @return Returns a numeric value.
* @author Dan Anderson (udf@sr77.com)
* @version 1.0, October 9, 2001
*/

function weekdays(date1,date2){
//initialize variables
var wday=0;
var day=0;
var numdays=0;

//get total number of days in between days and save it in numdays
numdays=datediff("d",date1,date2);
//loop through all the days between the dates.
for (day=0; day lte numdays; day=day+1){

if(dayofweek(dateadd("d",day,date1)) neq 1 and dayofweek(dateadd("d",day,date1)) neq 7){
//if the day is neither saturday or sunday add a week day.
wday=wday+1;}
}
return wday;
}
</cfscript>

Search CFLib.org


Latest Additions

Tony Blackmon Tony Blackmon added
generatePassword
6 hour(s) ago

Ben Garrett Ben Garrett added
isRFC3339
7 hour(s) ago

Raymond Camden Raymond Camden added
romanToDecimal
4 day(s) ago

Joe Rinehart Joe Rinehart added
directoryCopy
4 day(s) ago

Top Rated

Nick Giovanni                                     UniqueValueList
Rated 5.0, 5 time(s)

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Bobby Hartsfield                                  randStr
Rated 5.0, 3 time(s)

Rob Brooks-Bilson                                 FolderSize
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson