CFLib.org – Common Function Library Project

WeekStartDate(weekNum, weekYear[, ISOFormat])

Last updated March 19, 2002

author

David Murphy

Version: 1 | Requires: CF5 | Library: DateLib

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:

/**
 * 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;	
 }
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