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!

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Robert Kuykendall Sat, 26 Jul 2008 03:25:29 PDT

    Thank you :)

Comments