CFLib.org – Common Function Library Project

ISOYear(inputDate)

Last updated August 4, 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;
}
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