MovableBlog: Ordinal Numbers with MT and PHP

Nuance 2.0

December 7, 2002

A subtle change to the date headers here at MovableBLOG. There are now "st" after any date with the day of the month being 1 or 21, "nd" after the days of the month 2 and 22, "rd" after days of the month 3 and 23, as well as "th" for any other day of the month. I didn't find a solution in the MT manual, but it apppears there is a plugin which can convert dates in to ordinal numbers.

It probably would have done me some good to look in the MT forums, since a solution was already posted by billzeller. But since I took the time to code it myself, I might as well publish it:


$dateToday = <$MTEntryDate format="%e"$>;
switch ($dateToday)
case 1:
case 21:
case 31:
$dayEnding = "st";
case 2:
case 22:
$dayEnding = "nd";

case 3:
case 23:
$dayEnding = "rd";

$dayEnding = "th";

print "<$MTEntryDate format="%B %e"$>".$dayEnding.", <$MTEntryDate format="%Y"$>";


Play around with that last print statement to get the desired date format.

Posted by Richard at 1:12