CFLib.org – Common Function Library Project

firstDayOfWeek([date])

Last updated March 8, 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);
}
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