Rails provide us many features which are native to Rails and not ruby.
We can ordinalize a date in rails with a method provided by active_support known as ordinalize.
If we want to ordinalize today's date we can write :-
2.1.5 :01 > t = Time.now
=> 2015-12-30 15:20:58 +0530
2.1.5 :03 > t.strftime("#{tday.ordinalize} %B %Y")
=> "30th December 2015"
(Here B is used to display month's Name and Y display the year in 4-digit format)
Thus we can see that it appended th after the date i.e 30th, this is the ordinalized form.
0 Comment(s)