I want to get the Date in formation YYYY-MM-DD for the start of the
current year
But I cannot think how to do it…
This generates a name error .rhtml view.
<%= at_beginning_of_year.Time.now %>
I want to get the Date in formation YYYY-MM-DD for the start of the
current year
But I cannot think how to do it…
This generates a name error .rhtml view.
<%= at_beginning_of_year.Time.now %>
Le Mercredi 14 Juin 2006 09:34, Glenn C. a écrit :
I want to get the Date in formation YYYY-MM-DD for the start of the
current yearBut I cannot think how to do it…
This generates a name error .rhtml view.
<%= at_beginning_of_year.Time.now %>
This is almost good
Just try this instead : Time.now.at_beginning_of_year
It should work better
Cheers,
Loïc Guitaut wrote:
Le Mercredi 14 Juin 2006 09:34, Glenn C. a écrit :
I want to get the Date in formation YYYY-MM-DD for the start of the
current yearBut I cannot think how to do it…
This generates a name error .rhtml view.
<%= at_beginning_of_year.Time.now %>
This is almost good
Just try this instead : Time.now.at_beginning_of_year
It should work betterCheers,
Yes it works, but how do I now format the date to my desired format
(dates the way god intented )
YYYY-MM-DD
eg.
2007.01.01
Le Mercredi 14 Juin 2006 09:56, Glenn C. a écrit :
This is almost good
Just try this instead : Time.now.at_beginning_of_year
It should work betterCheers,
Yes it works, but how do I now format the date to my desired format
(dates the way god intented)
Ok, you’ll have to write something like this at the end of your
config/environment.rb :
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:my_beautiful_date => “%Y-%m-%d”
)
And now on any Time object you can call the to_s method with
the :my_beautiful_date parameter and it should work perfectly
So with your example it should be :
Time.now.at_beginning_of_year.to_s :my_beautiful_date
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs