CFLib.org – Common Function Library Project

weekNumsInMonth(month, year)

Last updated July 23, 2011

author

Robby L.

Version: 2 | Requires: CF5 | Library: DateLib

Description:
When given a month and year returns an array of weeks that are present in that month. By weeks we mean the numeric value from the week() function.

Return Values:
Returns an array.

Example:

<cfset foo = weekNumsInMonth(2,2003)>
<cfdump var="#foo#">

Parameters:

Name Description Required
month Month number. Yes
year Year number. Yes

Full UDF Source:

/**
 * Returns the week numbers in a given month of a given year.
 * v2 mods by RCamden to fix December issues
 * 
 * @param month 	 Month number. (Required)
 * @param year 	 Year number. (Required)
 * @return Returns an array. 
 * @author Robby L. (robby@ohsogooey.com) 
 * @version 2, July 23, 2011 
 */
function weekNumsInMonth(month,year) {
	var fakedate = createDate(year,month,1);
	var firstWeek = week(fakedate);
	var lastweek = week(createDate(year,month,daysInMonth(fakedate)));
	var i="";
	var aWeek = arrayNew(1);
	for(i=firstWeek;i lte lastWeek;i=i+1) {
		arrayAppend(aWeek, i);
	}
	return aWeek;
 }
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