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???

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 B. http://agileconsultingllc.com
[email protected]

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

On Mar 7, 11:07 am, Rob B. [email protected]

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