CFLib.org – Common Function Library Project

ISOYear(inputDate)

Last updated August 04, 2005

author

Pete Gibb

Version: 1 | Requires: CF5 | Library: DateLib

Description:
As ISOWeek is to Week(), ISOYear returns the ISOYear of the date input. For 360 days a year, this will be the same as Year(), but from the 29th Dec to 3rd Jan, is may be different. Dates in this range may be part of a week number of a year that differs to the actual year of the date.

Return Values:
Returns a string.

Example:

<cfloop index="x" from="1" to="8">
    <cfset testDate = dateAdd("d",x,"28/Dec/2005")>
    <cfoutput>
        Date: #dateFormat(testDate,"dddd dd/mmm/yyyy")# CF:#year(testDate)# ISO:#ISOYear(testDate)#<br>
    </cfoutput>
</cfloop>

Parameters:

Name Description Required
inputDate The date to format. Yes

Full UDF Source:

/**
 * Returns the ISO correct year of a given date, necessary for dates from 29th Dec to 3rd Jan.
 * 
 * @param inputDate      The date to format. (Required)
 * @return Returns a string. 
 * @author Pete Gibb (peter.gibb@icaew.co.uk) 
 * @version 1, August 4, 2005 
 */
function ISOYear(inputDate) {
    var inputDay = dayOfWeek(inputDate);
    var yearNo = year(inputDate);
    
    /** If the inputdate IS 29th-31st December, the input year MAY need to be next year **/
    if((dateFormat(inputDate,"ddmm") is "2912" and dayOfWeek(inputDate) eq 2)
    or (dateFormat(inputDate,"ddmm") IS "3012" and listFind("2,3",dayOfWeek(inputDate),",") gt 0)
    or (dateFormat(inputDate,"ddmm") IS "3112" and listFind("2,3,4",dayOfWeek(inputDate),",") gt 0))
    {yearNo=year(inputDate)+1;}
    
    /** If the inputdate IS 1st - 3rd January, the input year MAY need to be previous year **/
    if((dateFormat(inputDate,"ddmm") is "0301" and dayOfWeek(inputDate) eq 1)
    or (dateFormat(inputDate,"ddmm") IS "0201" AND listFind("1,7",dayOfWeek(inputDate),",") gt 0)
    or (dateFormat(inputDate,"ddmm") IS "0101" and listFind("1,7,6",dayOfWeek(inputDate),",") gt 0))
    {yearNo=year(inputDate)-1;}
    
    return yearNo;
}

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