amvis
2011-Dec-12 10:36 UTC
problem on subtract one year from current year in ruby on rails
For the ruby on rails application. i have to generate last one year report. so i think just do like this. Take the current system data, then subtract one year, den select data from MySQL with this new date. *my question is how to subtract one year from current date in ruby, basically 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") * * * *here just i change dat format to DD-MM-YYYY, and then try to subtract 1. But it shows error...* * * *how to solve this...? and have any problem in this logic......?* -- 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/-/vPxUt-jm5SYJ. 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-12 10:42 UTC
Re: problem on subtract one year from current year in ruby on rails
On 12 December 2011 10:36, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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, basically > 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")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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
BALA MANI
2011-Dec-12 12:09 UTC
Re: problem on subtract one year from current year in ruby on rails
> can you try like this way >time.to_s I hope it may work bye:) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim Ruther Nill
2011-Dec-12 12:37 UTC
Re: problem on subtract one year from current year in ruby on rails
On Mon, Dec 12, 2011 at 6:42 PM, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12 December 2011 10:36, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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, > basically > > 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") > > last_year = Time.now.ago(1.year) >for me, the following is much clearer last_year = 1.year.ago> 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 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
amvis
2011-Dec-12 16:56 UTC
Re: problem on subtract one year from current year in ruby on rails
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...? -- 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/-/odDlVwzseQYJ. 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.
Frederick Cheung
2011-Dec-12 17:34 UTC
Re: problem on subtract one year from current year in ruby on rails
On Dec 12, 4:56 pm, amvis <vgrkrish...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 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.
amvis
2011-Dec-13 05:33 UTC
Re: problem on subtract one year from current year in ruby on rails
* last_year* = 1.year.ago SELECT count(id) from customers where created_at > *"2010-12-13"* In the above query i need to change into a variable* last_year instead of "2010-12-13" *. and how to convert this MySQL query into rails query. also give me a link to study the rails queries 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/-/cnYC3lpN4a4J. 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.
Mukesh Singh
2011-Dec-13 05:43 UTC
Re: Re: problem on subtract one year from current year in ruby on rails
Read this http://guides.rubyonrails.org/active_record_querying.html On Tue, Dec 13, 2011 at 11:03 AM, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> * last_year* = 1.year.ago > > SELECT count(id) from customers where created_at > *"2010-12-13"* > > In the above query i need to change into a variable* last_year instead of > "2010-12-13" *. and how to convert this MySQL query into rails query. > also give me a link to study the rails queries > > 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/-/cnYC3lpN4a4J. > > 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. >-- Regards Mukesh Paras Singh -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
amvis
2011-Dec-13 08:06 UTC
Re: Re: problem on subtract one year from current year in ruby on rails
Thanks for the reply. get each month data between year. ie [ 2010-12-13 to 2011-12-13]. here i got this current date and last date in rails. have any idea to select that? i have to fetch the data in each month from database....? 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/-/U4YtbIgxum4J. 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-13 08:28 UTC
Re: Re: problem on subtract one year from current year in ruby on rails
On 13 Dec 2011 08:08, "amvis" <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> any idea to select that? i have to fetch the data in each month fromdatabase....? Yes. what have you tried? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
amvis
2011-Dec-13 08:40 UTC
Re: Re: problem on subtract one year from current year in ruby on rails
*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. -- 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/-/EDOEMIbFgrkJ. 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.