Richlewis
Richlewis

Reputation: 15374

change format of Date field in view

May be a simple question but i input dates into my model like so

<%= f.label :published_on, 'Published Date' %>
<%= f.date_select  :published_on, :order => [:day, :month, :year] %>

When creating the column from a migration i specified the column as :date

To output i use

which displays in this format

2013-01-01

How can i get this date to display

1st january 2014

I can convert a string into a date with this helper for example

def date_format(date)
date.to_date.strftime("#{date.to_date.day.ordinalize} %b %Y")
end

But doing it the other way around is throwing me

Thanks for any help

Upvotes: 0

Views: 163

Answers (1)

Ramiz Raja
Ramiz Raja

Reputation: 6030

Try this..

date.strftime('%e %B %Y')

visit this for more formats http://strfti.me/

Upvotes: 1

Related Questions