lastBusinessDay(strMonth[, strYear])
Last updated May 13, 2003
Version: 1 | Requires: CF5 | Library: DateLib
Description:
The purpose of this script is to get the last business day of any given month and year. Year is optional.
Return Values:
Returns a date object.
Example:
<cfset month = 11>
<cfset year = 2003>
<cfoutput>
Last business day of the month 11/2003 is:
#DateFormat(LastBusinessDayOfMonth(month,year), "dddd mmm dd, yyyy")#
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
strMonth | Month number. Should range from 1 to 12. | Yes |
strYear | Year. Defaults to this year. | No |
Full UDF Source:
/**
* Returns a date object representing the last Business day of the given month
*
* @param strMonth Month number. Should range from 1 to 12. (Required)
* @param strYear Year. Defaults to this year. (Optional)
* @return Returns a date object.
* @author Sravan K Erukulla (erukulla@yahoo.com)
* @version 1, May 13, 2003
*/
function LastBusinessDayOfMonth(strMonth) {
var strYear=Year(Now());
var busDay = false;
var tempDate = "";
if (ArrayLen(Arguments) gt 1) strYear=Arguments[2];
tempDate = DateAdd("d", -1, DateAdd("m", 1, CreateDate(strYear, strMonth, 1)));
while (busDay eq false) {
if (dayOfWeek(tempDate) GTE 2 AND dayOfWeek(tempDate) LTE 6) return tempDate;
else {
tempDate = DateAdd("d",-1,tempDate);
busDay = false;
}
}
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016