I am trying to figure out if a time stamp in my database is older then a month so that way my controller will only collect the one''s that are newer. So far I have @notes = @customer.notes.find(:all, :conditions => {:level => [''notice'', ''warning'', ''error'']}, :order => ''created_at DESC'') But I do not want it to show the once that are over a month old. Any ideas??? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 7, 2008, at 10:42 AM, InnerSparkMedia wrote:> I am trying to figure out if a time stamp in my database is older then > a month so that way my controller will only collect the one''s that are > newer. So far I have > > @notes = @customer.notes.find(:all, :conditions => {:level => > [''notice'', ''warning'', ''error'']}, :order => ''created_at DESC'') > > But I do not want it to show the once that are over a month old. Any > ideas???:conditions => [''level IN (?) AND created_at < ?'', [''notice'', ''warning'', ''error''], Time.now.months_ago(1)] You could have 1.month.ago or 30.days.ago depending on how you define "month" for your application. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
1.month.ago also works and it''s a bit tidier. On Mar 7, 11:07 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Mar 7, 2008, at 10:42 AM, InnerSparkMedia wrote: > > > I am trying to figure out if a time stamp in my database is older then > > a month so that way my controller will only collect the one''s that are > > newer. So far I have > > > @notes = @customer.notes.find(:all, :conditions => {:level => > > [''notice'', ''warning'', ''error'']}, :order => ''created_at DESC'') > > > But I do not want it to show the once that are over a month old. Any > > ideas??? > > :conditions => [''level IN (?) AND created_at < ?'', > [''notice'', ''warning'', ''error''], > Time.now.months_ago(1)] > You could have 1.month.ago or 30.days.ago depending on how you define > "month" for your application. > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
InnerSparkMedia wrote:> I am trying to figure out if a time stamp in my database is older then > a month so that way my controller will only collect the one''s that are > newer. So far I have > > @notes = @customer.notes.find(:all, :conditions => {:level => > [''notice'', ''warning'', ''error'']}, :order => ''created_at DESC'') > > But I do not want it to show the once that are over a month old. Any > ideas???1.month.ago.to_s(:db) to avoid the warnings in your db log.. :) hth ilan -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---