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

Shawn Porter Shawn Porter added
DeMoronize
3 hour(s) ago

Chris Carey Chris Carey added
readPropertiesFi...
1 day(s) ago

Randy Johnson Randy Johnson added
lastDayofWeek
3 day(s) ago

Frank Marion Frank Marion added
sitemapPing
7 day(s) ago

Top Rated

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Barney Boisvert indentXml
Rated 5.0, 3 time(s)

Nathan Dintenfass                                 queryColumnsToSt...
Rated 5.0, 3 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson