CFLib.org – Common Function Library Project

getCurrentFinYear(mask [, date])

Last updated May 26, 2003
Download UDF

author

Toby Tremayne                                     Toby Tremayne

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

 
Rated 0 time(s). Average Rating: 0

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:

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

Search CFLib.org


Latest Additions

Tony Felice Tony Felice added
writeStateSelect
14 hour(s) ago

Tony Felice Tony Felice added
varNameToText
14 hour(s) ago

Larry C. Lyons Larry C. Lyons added
splitMX
14 hour(s) ago

Tony Felice Tony Felice added
listIsItemSimila...
14 hour(s) ago

Tony Felice Tony Felice added
listCountItemSim...
14 hour(s) ago

Top Rated

Rob Brooks-Bilson                                 ListCompare
Rated 5.0, 6 time(s)

Nathan Dintenfass                                 QueryStringChang...
Rated 5.0, 4 time(s)

Rob Brooks-Bilson                                 FormatSSN
Rated 5.0, 2 time(s)

Ben Forta                                         DollarAsString
Rated 5.0, 2 time(s)

Ed Hodder                                         CapFirstTitle
Rated 5.0, 2 time(s)

Created by Raymond Camden / Design by Justin Johnson