CFLib.org – Common Function Library Project

firstDayOfWeek([date])

Last updated March 08, 2014

author

Pete Ruckelshaus

Version: 2 | Requires: CF9 | Library: DateLib

Description:
Returns the date for the first day of the week for a passed in date object. Assumes Sunday as the first day of the week.

Return Values:
Returns a date.

Example:

<cfoutput>#firstDayOfWeek(now())#</cfoutput>

Parameters:

Name Description Required
date Date object used to figure out week. No

Full UDF Source:

/**
 * Analogous to firstDayOfMonth() function.
 * v1.0 by Pete Ruckelshaus
 * v2.0 by Randy Johnson (made the date argument optional)
 * v2.1 by Adam Cameron (simplified logic)
 * 
 * @param date      Date object used to figure out week. (Optional)
 * @return Returns a date. 
 * @author Pete Ruckelshaus (pruckelshaus@yahoo.com) 
 * @version 2.1, March 8, 2014 
 */
date function firstDayOfWeek(date date=now()){
    return dateAdd("d", -(dayOfWeek(date)-1), date);
}

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