Thursday, March 11, 2010

Superscript Day in Date (eg: 1st, 2nd, 3rd, 4th, etc.)

Ever need to format a date into a readable format with the day followed by the two letter ending sound, eg: 1st, 2nd, 3rd, 4th, etc.

No easy way to do this but here is 'a way':
<cfset thedate=" now()">
<cfset superscriptlist="stndrdthththththththththththththththththstndrdthththththththst">
<cfset superscript=" mid(superScriptList,(day(theDate)*2)-1,2)">
<cfoutput>#dateformat(theDate,'Mmmm d')#<sup>#superScript#</sup>, #dateformat(theDate,'yyyy')#</cfoutput>

Input: now() (in this case {ts '2010-03-11 00:00:00'} )
Output: March 11th, 2010

2 comments:

  1. I don't know that I'd say that copying your code isn't easy.

    ReplyDelete
  2. I don't know that I'd say that copying your code isn't easy.

    ReplyDelete