CFLib.org – Common Function Library Project

ISOWeek(inputDate)

Last updated January 12, 2004

author

Ron Pasch

Version: 1 | Requires: CF5 | Library: DateLib

Description:
CF returns weeknumbers that are not according to the ISO standard. This UDF does.

Return Values:
Returns a number.

Example:

ISOWeek(dateObject)<cfloop index="x" from=1 to=200>
	<cfset dateObject = dateAdd("d",x,now())>
	<cfoutput>#week(dateObject)# versus #ISOWeek(dateObject)#<br></cfoutput>
</cfloop>

Parameters:

Name Description Required
inputDate Date object. Yes

Full UDF Source:

/**
 * Returns the weeknumber according to the ISO standard.
 * 
 * @param inputDate 	 Date object. (Required)
 * @return Returns a number. 
 * @author Ron Pasch (pasch@cistron.nl) 
 * @version 1, January 12, 2004 
 */
function ISOWeek(inputDate) {  
    var d = StructNew();
	var d2 = 0;
	var days = 0;
	d.yday = DayOfYear(inputDate);
	d.wday = DayOfWeek(inputDate)-1;
	d.year = Year(inputDate);
    days = d.yday - ((d.yday - d.wday + 382) MOD 7) + 3;
    if(days LT 0) {
        d.yday = d.yday + 365 + isLeapYear(d.year-1);
        days = d.yday - ((d.yday - d.wday + 382) MOD 7) + 3;
    } else {
        d.yday = (d.yday - 365) + isLeapYear(d.year);
        d2 = d.yday - ((d.yday - d.wday + 382) MOD 7) + 3;
        if (0 LTE d2) {
            days = d2;
        }
    }
	return int((days / 7) + 1);
}
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