get all the month between 2 year in ruby on rails

13 views
Skip to first unread message

amvis

unread,
Dec 14, 2011, 4:37:41 AM12/14/11
to rubyonra...@googlegroups.com
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

Michael Pavling

unread,
Dec 14, 2011, 4:39:00 AM12/14/11
to rubyonra...@googlegroups.com

What have you tried? Where have you looked for solutions? What
problems have you encountered?

Message has been deleted

Colin Law

unread,
Dec 14, 2011, 3:33:05 PM12/14/11
to rubyonra...@googlegroups.com
On 14 December 2011 19:45, amvis <vgrkr...@gmail.com> 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

Reply all
Reply to author
Forward
0 new messages