CFLib.org – Common Function Library Project

ISOWeek(inputDate)

Last updated January 12, 2004
Download UDF

author

Ron Pasch                                         Ron Pasch

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

 
Rated 2 time(s). Average Rating: 4.5

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:

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