CFLib.org – Common Function Library Project

WeekStartDate(weekNum, weekYear [, ISOFormat])

Last updated March 19, 2002
Download UDF

author

David Murphy                                      David Murphy

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

 
Rated 1 time(s). Average Rating: 5.0

Description:
Takes a week number and returns a date object of the first day of that week. This can be useful if you want to display an actual date that can be easily understood by a person as opposed to a week number. By default, Sunday is considered the first day of the week. If you pass the optional ISOFormat argument, you can set Monday as the first day of the week.

Return Values:
Returns a date object.

Example:

<cfoutput>
This data was aquired the week of #dateFormat(weekStartDate(12,2002),"mm/dd/yyyy")#
</cfoutput>

Parameters:

Name Description Required
weekNum The week number. Yes
weekYear The year. Yes
ISOFormat Use ISO for first day of week. Defaults to false. No

Full UDF Source:

<cfscript>
/**
* Takes a week number and returns a date object of the first day of that week.
* Added ISOFormat, RCamden, 3/19/2002
*
* @param weekNum      The week number.
* @param weekYear      The year.
* @param ISOFormat      Use ISO for first day of week. Defaults to false.
* @return Returns a date object.
* @author David Murphy (dmurphy52@lycos.com)
* @version 1, March 19, 2002
*/

function weekStartDate(weekNum,weekYear) {
    var weekDate = dateAdd("WW",weekNum-1,"1/1/" & weekYear);
    var toDay1 = dayofweek(weekDate)-1;
    var weekStartDate = dateAdd("d",-toDay1,weekDate);
    if(arrayLen(arguments) gte 3 and arguments[3]) weekStartDate = dateAdd("d",1,weekStartDate);
    return weekStartDate;    
}
</cfscript>

Search CFLib.org


Latest Additions

Shawn Porter Shawn Porter added
DeMoronize
3 hour(s) ago

Chris Carey Chris Carey added
readPropertiesFi...
1 day(s) ago

Randy Johnson Randy Johnson added
lastDayofWeek
3 day(s) ago

Frank Marion Frank Marion added
sitemapPing
7 day(s) ago

Top Rated

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Barney Boisvert indentXml
Rated 5.0, 3 time(s)

Nathan Dintenfass                                 queryColumnsToSt...
Rated 5.0, 3 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson