# Timestamp help

**URL:** <https://www.ruby-forum.com/t/timestamp-help/131280>\
**Category:** Rails\
**Created:** [March 7, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/timestamp-help/131280 "2008-03-07T16:43:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [March 7, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/timestamp-help/131280/1 "2008-03-07T16:43:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [March 7, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/timestamp-help/131280/2 "2008-03-07T17:08:59Z")

</div>

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](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [March 8, 2008, 8:49pm UTC](https://www.ruby-forum.com/t/timestamp-help/131280/3 "2008-03-08T20:49:10Z")

</div>

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

On Mar 7, 11:07 am, Rob B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![InnerSparkMedia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/d07c76/32.png) [@InnerSparkMedia](https://www.ruby-forum.com/u/InnerSparkMedia)\
**Post date:** [March 8, 2008, 9:17pm UTC](https://www.ruby-forum.com/t/timestamp-help/131280/4 "2008-03-08T21:17:24Z")

</div>

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
