CFLib.org – Common Function Library Project

firstDayOfWeek(date)

Last updated September 12, 2007

Version: 1 | Requires: ColdFusion 5 | Library: DateLib

 
Rated 1 time(s). Average Rating: 5.0

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:

view plain print about
<cfoutput>#firstDayOfWeek(now())#</cfoutput>

Parameters:

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

Full UDF Source:

view plain print about
<cfscript>
/**
 * Analogous to firstDayOfMonth() function.
 * 
 * @param date      Date object used to figure out week. (Required)
 * @return Returns a date. 
 * @author Pete Ruckelshaus (pruckelshaus@yahoo.com) 
 * @version 1, September 12, 2007 
 */

function firstDayOfWeek(date) {
    var dow = "";
    var dowMod = "";
    var dowMult = "";
    var firstDayOfWeek = "";
    date = trim(arguments.date);
    dow = dayOfWeek(date);
    dowMod = decrementValue(dow);
    dowMult = dowMod * -1;
    firstDayOfWeek = dateAdd("d", dowMult, date);
    
    return firstDayOfWeek;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson