getWeekEnding(theMonth, theYear)
Last updated January 13, 2004
Version: 1 | Requires: ColdFusion 5 | Library: DateLib
Description:
Returns an array of dates with the week ending date of each week in the month. The code defaults to friday as the week ending as this would typically be useful when creating some sort of business report.
Return Values:
Returns an array.
Example:
<cfdump var="#getWeekEnding(month(now()),year(now()))#">
Parameters:
| Name | Description | Required |
|---|---|---|
| theMonth | Month to use. | Yes |
| theYear | Year to use. | Yes |
Full UDF Source:
<cfscript>
/**
* Returns an array of dates with the week ending date of each week in the month.
*
* @param theMonth Month to use. (Required)
* @param theYear Year to use. (Required)
* @return Returns an array.
* @author Brian Rinaldi (brinaldi@criticaldigital.com)
* @version 1, January 13, 2004
*/
function getWeekEnding(theMonth,theYear) {
/**
* week ending day is a friday for our purposes as the end of the business week
* this can be modified to return a week ending on whatever day you want
*/
var endOfWeek = 6;
var theDay = 0;
var i = 1;
var arrDate = arrayNew(1);
var theDate = "";
// loop to find the first friday of the month
do {
theDay = theDay + 1;
} while (dayOfWeek(createDate(theYear,theMonth,theDay)) NEQ endOfWeek);
// establish the first friday of the month
theDate = createDate(theYear,theMonth,theDay);
// set the first week end date in the array
arrDate[i] = theDate;
/**
* loop through the rest of the month adding seven to the date until the date
* exceeds the end of the month
*/
i=i+1;
while (month(dateAdd('d',7,theDate)) EQ theMonth) {
theDate = dateAdd('d',7,theDate);
arrDate[i] = theDate;
i = i + 1;
}
return arrDate;
}
</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)