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 %> -- Posted via http://www.ruby-forum.com/.
Le Mercredi 14 Juin 2006 09:34, Glenn Cadman a ?crit?:> 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 %>This is almost good ;) Just try this instead : Time.now.at_beginning_of_year It should work better Cheers, -- ,= ,-_-. =. Lo?c Guitaut ((_/)o o(\_)) http://www.belfalas.org `-''(. .)`-'' Jabber ID : Flink@im.apinc.org \_/ GnuPG KeyID : 0xA78CD85D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060614/42cefe39/attachment.bin
Lo?c Guitaut wrote:> Le Mercredi 14 Juin 2006 09:34, Glenn Cadman a ?crit?: >> 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 %> > > This is almost good ;) > > Just try this instead : Time.now.at_beginning_of_year > It should work better > > Cheers,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 -- Posted via http://www.ruby-forum.com/.
Le Mercredi 14 Juin 2006 09:56, Glenn Cadman a ?crit?:> Lo?c Guitaut wrote: > > Le Mercredi 14 Juin 2006 09:34, Glenn Cadman a ?crit?: > >> 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 %> > > > > This is almost good ;) > > > > Just try this instead : Time.now.at_beginning_of_year > > It should work better > > > > Cheers, > > 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 -- ,= ,-_-. =. Lo?c Guitaut ((_/)o o(\_)) http://www.belfalas.org `-''(. .)`-'' Jabber ID : Flink@im.apinc.org \_/ GnuPG KeyID : 0xA78CD85D -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060614/b5e533f0/attachment.bin