CFLib.org – Common Function Library Project

dateLetters(dateStr[, formatStr])

Last updated May 22, 2003

author

Ian Winter

Version: 1 | Requires: CF5 | Library: DateLib

Description:
This will return a given date in a long formated string including the optional letters ie 1st,2nd,3rd,4th etc.

Return Values:
Returns a string.

Example:

<cfoutput>
#dateLetters(now())#
</cfoutput>

Parameters:

Name Description Required
dateStr Date to use. Yes
formatStr Format string for month and year. No

Full UDF Source:

/**
 * Add's the st,nd,rd,th after a day of the month.
 * 
 * @param dateStr 	 Date to use. (Required)
 * @param formatStr 	 Format string for month and year. (Optional)
 * @return Returns a string. 
 * @author Ian Winter (ian@defusionx.om) 
 * @version 1, May 22, 2003 
 */
function dateLetters(dateStr) {
	var letterList="st,nd,rd,th";
	var domStr=DateFormat(dateStr,"d");
	var domLetters='';
	var formatStr = "";

	if(arrayLen(arguments) gte 2) formatStr = dateFormat(dateStr,arguments[2]);

	switch (domStr) {
		case "1": case "21": case "31":  domLetters=ListGetAt(letterList,'1'); break;
		case "2": case "22": domLetters=ListGetAt(letterList,'2'); break;
		case "3": case "23": domLetters=ListGetAt(letterList,'3'); break;
		default: domLetters=ListGetAt(letterList,'4');
	}

	return domStr & domLetters & " " & formatStr;
}
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