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);
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson