CFLib.org – Common Function Library Project

weekNumsInMonth(month, year)

Last updated July 24, 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;
 }

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

Created by Raymond Camden / Design by Justin Johnson