CFLib.org – Common Function Library Project

ThisWeek([date])

Last updated February 25, 2002

author

Rich Rein

Version: 2 | Requires: CF5 | Library: DateLib

Description:
Pass in a date, or use the default of today, and this function will generate a structure containing a set of keys relevant to the week. Keys include: weekBegin, weekEnd, weekNo (week number of the year), Sunday, Monday, etc.

Return Values:
Returns a structure.

Example:

<cfset weekData = thisWeek()>
<cfdump var="#weekData#">
<cfset nextWeek = dateAdd("d",7,now())>
<cfset nweekData = thisWeek(nextWeek)>
<cfdump var="#nweekData#">

Parameters:

Name Description Required
date Date to use. Defaults to this week. No

Full UDF Source:

/**
 * Generates a structure of days for the week, including the beginning and end of the week.
 * Rewrite by Raymond Camden
 * 
 * @param date 	 Date to use. Defaults to this week. 
 * @return Returns a structure. 
 * @author Rich Rein (richard.rein@medtronic.com) 
 * @version 2, February 25, 2002 
 */
function thisWeek() {
	var dayOrdinal = 0;
	var returnStruct = structNew();
	var current_date = now();
	
	if (arrayLen(arguments)) current_date = arguments[1];
	dayOrdinal = DayOfWeek(current_date);
	
	returnStruct.weekBegin = dateAdd("d",-1 * (dayOrdinal-1), current_date);
	returnStruct.weekEnd = dateAdd("d",7-dayOrdinal, current_date);
	returnStruct.weekNo = Week(returnStruct.weekBegin);
	
	for(i=1; i LTE 7; i=i+1) {
		StructInsert(returnStruct,DayOfWeekAsString(i),dateAdd("d",i-1,returnStruct.weekBegin));
	}
	
	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