i take the current date and find the last year in ruby with *1.year.ago. so i got 2 years 2010-12-14 to 2011-12-14. My question is how to get all the months between these two dates in ruby in rails...? also these dates will change depend on the current system date...* * * *thank you* *vishnu* -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/yVFmqtipxtgJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2011-Dec-14 09:39 UTC
Re: get all the month between 2 year in ruby on rails
On 14 December 2011 09:37, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i take the current date and find the last year in ruby with 1.year.ago. so > i got 2 years 2010-12-14 to 2011-12-14. My question is how to get all the > months between these two dates in ruby in rails...? also these dates will > change depend on the current system date...What have you tried? Where have you looked for solutions? What problems have you encountered? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
@lastyear = 1.year.ago. it will give the last year. but it will shows date with time. 2010-12-14 19:44:28 UTC How to avoid that time...? i have to get only the date 2010-12-14... Thank you vishnu -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/mPrqf1kwynQJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 December 2011 19:45, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @lastyear = 1.year.ago. it will give the last year. but it will shows date > with time. > > 2010-12-14 19:44:28 UTC > > How to avoid that time...? i have to get only the date 2010-12-14...Have a look at the documentation for the Time class, there are many methods that you can use. When you say you want to "get" the date do you mean you want it in a variable or you want to convert it to a string for display? If you want it in a variable then you can make a new Time object using day, month, year from original one (leaving hours, mins, seconds as zero so it represents the start of the day). If you want it as a string then look at strftime. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.