Rob Biedenharn wrote: > On Apr 21, 2009, at 9:26 AM, Nike Mike wrote: > >> >> Can anyone give a suggestion so that i can able to format the date as >> like this 3th - 5th June 2009 >> -- > > irb> require 'date' > => [] > irb> Date::MONTHNAMES > => [nil, "January", "February", "March", "April", "May", "June", > "July", "August", "September", "October", "November", "December"] > irb> myformat = lambda {|date| "%s %s %d"%[date.mday.ordinalize, > Date::MONTHNAMES[date.month], date.year] } > => #<Proc:0x00007ff7862efcb8@(irb):7> > irb> myformat[Date.today] > => "21st April 2009" > > That ought to be enough of a suggestion! Note that this is inside a > Rails console so if you did this in plain Ruby, you'd have to require > 'rubygems' and require 'activesupport' to get Fixnum#ordinalize > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > r...@agileconsultingllc.com
Or you could use Date.today.strftime("%d %m %Y"), though you wouldn't get the extension ('st'). Use a simple case statement on the last digit if you can't or won't use ActiveSupport. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---