Weekdays(date1, date2)
Last updated October 9, 2001
Version: 1 | Requires: ColdFusion 5 | Library: DateLib
Description:
Returns the number of weekdays between two dates.
Return Values:
Returns a numeric value.
Example:
<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 added
DeMoronize
3 hour(s) ago
Chris Carey added
readPropertiesFi...
1 day(s) ago
Randy Johnson added
lastDayofWeek
3 day(s) ago
Frank Marion added
sitemapPing
7 day(s) ago
Top Rated
QuickSort
Rated 5.0, 3 time(s)
indentXml
Rated 5.0, 3 time(s)
queryColumnsToSt...
Rated 5.0, 3 time(s)
generateSsccAsn
Rated 5.0, 3 time(s)