CFLib.org – Common Function Library Project

thisMonth([current_date])

Last updated July 25, 2005

author

Ian Winter

Version: 1 | Requires: CF6 | Library: DateLib

Description:
Returns structure containing information about the month including date object for each day, each day as a string and each day's date letters ie "st,nd,rd,th". Also start and end day as entries, number of days in that month and the month number.

Return Values:
Returns a structure.

Example:

<cfset thisMonthData = thisMonth()>
<cfdump var="#thisMonthData#">
<cfset nextMonth = dateAdd("m",1,now())>
<cfset nextMonthData = thisMonth(nextMonth)>
<cfdump var="#nextMonthData #">

Parameters:

Name Description Required
current_date The date to use. Defaults to now(). No

Full UDF Source:

/**
 * Returns structure containing month information.
 * 
 * @param current_date 	 The date to use. Defaults to now(). (Optional)
 * @return Returns a structure. 
 * @author Ian Winter (ianwinter@gmail.com) 
 * @version 1, July 25, 2005 
 */
function thisMonth() {
	var returnStruct = structNew();
	var current_date = now();
	var letterList="st,nd,rd,th";
	var domLetters="";
	var i = "";
	var thisDate = "";
	var thisKey = "";
	var domStr = "";
	
	if (arrayLen(arguments)) current_date = arguments[1];
	
	returnStruct.monthBegin = CreateDate(Year(current_date),Month(current_date),01);
	returnStruct.monthEnd = CreateDate(Year(current_date),Month(current_date),DaysInMonth(current_date));
	returnStruct.monthNumber = Month(current_date);
	returnStruct.monthDays = DaysInMonth(current_date);
	
	for(i=1; i LTE returnStruct.monthDays ; i=i+1) {
		thisDate = CreateDate(Year(current_date),Month(current_date),i);
		thisKey = dateAdd("d",i-1,returnStruct.monthBegin);
		domStr = DateFormat(thisDate,"d");
		switch (domStr) {
			case "1": case "21": case "31":  domLetters=ListGetAt(letterList,'1'); break;
			case "2": case "22": domLetters=ListGetAt(letterList,'2'); break;
			case "3": case "23": domLetters=ListGetAt(letterList,'3'); break;
			default: domLetters=ListGetAt(letterList,'4');
		}
		StructInsert(returnStruct,i,StructNew());
		StructInsert(returnStruct[i],"dayAsString",DayOfWeekAsString(DayOfWeek(thisDate)));
		StructInsert(returnStruct[i],"date",thisKey);
		StructInsert(returnStruct[i],"dateLetters",domLetters);
	}
	
	return returnStruct;

}
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