CFLib.org – Common Function Library Project

Weekdays(date1, date2)

Last updated October 9, 2001

author

Dan Anderson

Version: 1 | Requires: CF5 | Library: DateLib

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:

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