CFLib.org – Common Function Library Project

yearAsString(yearnum)

Last updated March 17, 2006

author

Christopher Jewell

Version: 2 | Requires: CF5 | Library: DateLib

Description:
An updated version of Larry Juncker's version with the following enhancements/fixes: 1. Won't puke on 1990, 2000, etc. 2. Writes out 2011 as "Two Thousand and Eleven" instead of "Two Thousand and Ten One". 3. Corrects the misspelling of "Forty". Only good for the year 1000 and later.

Return Values:
Returns a string.

Example:

2000 = #YearAsString(2000)#

Parameters:

Name Description Required
yearnum Numeric year. Yes

Full UDF Source:

/**
 * Returns a string representation of the numeric year passed into it.
 * version 1 by Larry Juncker (ljuncker@aljcompserv.com)
 * 
 * @param yearnum 	 Numeric year. (Required)
 * @return Returns a string. 
 * @author Christopher Jewell (cdjewell@gmail.com) 
 * @version 2, March 17, 2006 
 */
function yearAsString(yearnum) {
    var numTenList="Ten,Twenty,Thirty,Forty,Fifty,Sixty,Seventy,Eighty,Ninety";
    var numList="One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Eleven,Twelve,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,Eighteen,Nineteen";
    var y1 = mid(yearnum,1,1);
    var y2 = mid(yearnum,2,1);
    var y3 = mid(yearnum,3,1);
    var y4 = mid(yearnum,4,1);
	var YY = mid(yearnum,3,2);
    var y2Str = "";
    var y3Str = "";
    var y4Str = "";
	var yearStr = "";

    if(y2 GT 0) y2Str = listGetAt(numList,y2) & " Hundred";
	
	//Special case for XX11 through XX19
	if(YY gt 10 and YY lt 20) {
		y3Str = listGetAt(numList,YY);
	} else {
	    if(y3 GT 0) y3Str = listGetAt(numTenList,y3);
		if(y4 GT 0) y4Str = listGetAt(numList,y4);
	}

	if(len(y3Str) or len(y4Str)) {
		yearStr = listGetAt(numList,y1) & " Thousand "   & y2Str & " " &  " and " & y3Str & " " & y4Str;
	} else {
		yearStr = listGetAt(numList,y1) & " Thousand "   & y2Str;
	}
	return trim(yearStr);
}
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