Formatting dates nicely in Rails
I always thought those “today”, “yesterday”, “4 days ago” date references on some websites way cool. On a small system I’m working on I did some code to do something alike, though in portuguese. But if you want it in english, there’s a small plugin called relative_time_helpers that you can install by typing:
script/plugin install http://ar-code.svn.engineyard.com/plugins/relative_time_helpers/
Then, you can do things like
<%= relative_time(Time.now) %> # today <%= relative_time(1.day.ago) %>< # yesterday <%= relative_time(1.day.from_now) %> # tomorrow <%= relative_time_span([Time.now, 5.days.from_now]) %># May 17th - 22nd
This tip was taken from Active Reload Blog!