timestamp help

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@AgileConsultingLLC.com

1.month.ago also works and it's a bit tidier.

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.. :slight_smile:

hth

ilan