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

Then, you can do things like

<%= relative_time( %>
# today

<%= relative_time( %><
# yesterday

<%= relative_time( %>
# tomorrow

<%= relative_time_span([, 5.days.from_now]) %># May 17th - 22nd

This tip was taken from Active Reload Blog!


~ by Dante Regis on August 16, 2007.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: