Ordinalize Date in Rails 1

Posted by Matt on March 06, 2008

Scratched my head for a tick when I noticed that Ruby’s Date::strftime doesn’t include a ordinal formatting option (eg. “January 1st, 2008”). To get the “st/nd/th/rd” in the formatted output, do this:

date.strftime("%B #{date.day.ordinalize}, %Y")

Hope this helps someone out there!