views:

73

answers:

2

so i create in my view:

<%=date=Date.today%>

How do i get the name of the month out of the date? I was trying to do sth like

 <%= DATE::ABBR_MONTHNAMES(date.month)%>    

But without success. I keep getting an error: uninitialized constant ActionView::Base::CompiledTemplates::MONTHNAMES

How do i initialise the constant or is there any other way to get the name out of the Date format?

would greatly appreciate any answers!

+8  A: 

Ref this

<% @date = Date.today  %>  
<%= @date.strftime("%B")%>

if

@date >> Fri, 11 Jun 2010

then

@date.strftime("%B") >> "June"

Salil
+3  A: 

If you have a particular custom date / time format which you need to use repeatedly then you can extend the ActiveSupport date / time helper.

e.g. if you define the following in your config/environment.rb

ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:full_english => "%A %B %d, %Y at %I:%M %p")

then when you call Time.now.to_s(:full_english) in your views you will get something like:

"Friday June 11, 2010 at 12:53 PM"

Ruby's strftime method is well documented at http://apidock.com/ruby/Time/strftime

edavey
Look at date/time converters to_formatted_s. This allows you to define date formats (like `:month_only`) and use date.to_formatted_s(:month_only) so you get maximum reuse for your strftime usage.
Dmitriy Likhten