last_year = Time.now.ago(1.year)
records = MyModel.all(:conditions => ["my_date_field > ?", last_year])
Have a look at the api commands around dates and times:
http://api.rubyonrails.org/classes/Time.html
can you try like this way
On 12 December 2011 10:36, amvis <vgrkr...@gmail.com> wrote:
> For the ruby on rails application. i have to generate last one year report.
>
> my question is how to subtract one year from current date in ruby, basicallylast_year = Time.now.ago(1.year)
> the format of date in MySql is YYYY-MM-DD. so how to subtract one year from
> this.
>
> i tried one..
>
> time = Time.new
> puts ddat = time.strftime("%d-%m-%Y")
records = MyModel.all(:conditions => ["my_date_field > ?", last_year])
Have a look at the api commands around dates and times:
http://api.rubyonrails.org/classes/Time.html
--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 12, 4:56 pm, amvis <vgrkrish...@gmail.com> wrote:
> in my machine i dn't have the local application setup. so just i try this
> two for display that
>
> *puts last_year = Time.now.ago(1.year) *or* last_year = 1.year.ago*
>
> but it gives error *undefined method `year' for 1:Fixnum (NoMethodError).*year is builtin...?
The 1.year.ago stuff is rails only, so if you were in a pure ruby
console it wouldn't work
Fred
--
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/-/cnYC3lpN4a4J.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 13 Dec 2011 08:08, "amvis" <vgrkr...@gmail.com> wrote:
> any idea to select that? i have to fetch the data in each month from database....?
Yes. what have you tried?
Date.today.month or Time.now.month to get the month then how will continue. i think about that on how to continue. But i can't proceed. i need to take the each month report from the one year.