Ruby on Rails – Easy date display Nov
19

I have created this simple format_date method to format dates differently and put it in the ApplicationHelper. I know it isn’t something that is a super WOW factor but thought I would share anyways.

  def format_date(type, date)
    case type
      when :short_no_year 
        date.strftime("%b %d")
      when :short
        date.strftime("%b %d, %y")
      when :long 
        date.strftime("%B %d, %Y")
      when :long_day_of_week
        date.strftime("%a %B %d, %Y")
      when :default
        date.strftime("%m.%d.%Y")
    end
  end

to call in your view just use

<%=format_date(:long, crappy_date_from_db) %>

Comments (1)

  • Your twitter button is one of the cutest, most well-designed things I’ve seen in a while. Love it!

Leave a comment