Formatting a date object to display a human readable date

Viewed 40752

Here's what I'd like to display:

May 13, 2012

Here's what is being displayed:

2012-05-13

I searched for some answers and it led me to "Formatting Dates and Floats in Ruby", where it mentions a possible solution:

<p class="date"><%= @news_item.postdate.to_s("%B %d, %Y") %></p>

However this doesn't change the output at all. No debugging errors, or exceptions are fired.

I can do this and it works perfectly fine:

<p class="date"><%= Time.now.to_s("%B %d, %Y") %></p>

Here is my migration file (to see what data type I used):

class CreateNewsItems < ActiveRecord::Migration
  def change
    create_table :news_items do |t|

      t.date :postdate

      t.timestamps
    end
  end
end
3 Answers
<%= time_ago_in_words @user.created_at %>

result: 9 hours ago

Related