CFLib.org – Common Function Library Project

getCurrentFinYear(mask[, date])

Last updated May 26, 2003

author

Toby Tremayne

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Calculates the current financial year and passes it back in the format specified. Pass a format mask to this function using "y1" to denote the first half year and "y2" for the second. For instance to request the financial year returned in the format: "2002/2003" use: getCurrentFinYear("y1/y2");

Return Values:
Returns a string.

Example:

<cfoutput>
#getCurrentFinYear("y1/y2")#
</cfoutput>

Parameters:

Name Description Required
mask Formats result using y1 and y2. Yes
date Date to use. Defaults to now(). No

Full UDF Source:

/**
 * Returns the current two-part financial year in a specified format.
 * 
 * @param mask 	 Formats result using y1 and y2. (Required)
 * @param date 	 Date to use. Defaults to now(). (Optional)
 * @return Returns a string. 
 * @author Toby Tremayne (toby@lyricist.com.au) 
 * @version 1, May 26, 2003 
 */
function getCurrentFinYear(mask) {
 	var finYear = "";
	var partOne = "";
	var partTwo = "";
	var date = now();

	if(arrayLen(arguments) gte 2) date = arguments[2];
	
	// if the current month falls in the first 6 months of the year...
	if (month(date) lte 6) {
		// first part is last year
		partOne = year(dateAdd("yyyy", -1, date));
		// second part is this year
		partTwo = year(date);
	} else {
		// first part is this year
		partOne = year(date);
		// second part is next year
		partTwo = year( dateAdd("yyyy", 1, date) );
	}
	// replace mask tokens for return
	finYear = replaceNoCase(mask,"y1",partOne);
	finYear = replaceNoCase(finYear,"y2",partTwo);
	
	return finYear;
}
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