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;

}

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