I've been using the following bit of code in my Visualforce pages to get the so called ordinal indicators (the 'st', 'nd', 'rd', and 'th' in 1st, 2nd, 3rd, 4th) when formatting dates.

<apex:outputText value="{!CASE(MOD(DAY(TODAY()),10),1,"st",2,"nd",3,"rd","th")}"/>

It's clunky however and isn't friendly when using <apex:param> tags. I was wondering if anyone had any tricks to accomplish this nicely. I'd prefer not to create a method in the controller to do this as I it would involved writing more unit tests.

  • You are already using Case function, what problem are you facing with apex:param?
    – Raul
    Feb 21, 2017 at 19:08
  • For instance if I want to use something like this <apex:outputText value="{0,date,MMM'. 'ddd}{1}', '{0,date,yyyy}"><apex:param value="{!account.LastModifiedDate}"/><apex:param value="{!CASE(MOD(DAY(account.LastModifiedDate.date()),10),1,"st",2,"nd",3,"rd","th")}"></apex:outputText> it just starts to get messy
    – Josh D
    Feb 21, 2017 at 19:42


You must log in to answer this question.

Browse other questions tagged .