– Common Function Library Project

getWeekEnding(theMonth, theYear)

Last updated January 13, 2004


Brian Rinaldi

Version: 1 | Requires: CF5 | Library: DateLib

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.


dump of week ending dates for the current month/year:

<cfdump var="#getWeekEnding(month(now()),year(now()))#">


Name Description Required
theMonth Month to use. Yes
theYear Year to use. Yes

Full UDF Source:

 * 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 ( 
 * @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
	while (month(dateAdd('d',7,theDate)) EQ theMonth) {
		theDate = dateAdd('d',7,theDate);
		arrDate[i] = theDate;
		i = i + 1;
	return arrDate;
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson