# Find by compared date

**URL:** <https://www.ruby-forum.com/t/find-by-compared-date/114215>\
**Category:** Rails\
**Created:** [September 10, 2007, 1:54am UTC](https://www.ruby-forum.com/t/find-by-compared-date/114215 "2007-09-10T01:54:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [September 10, 2007, 1:54am UTC](https://www.ruby-forum.com/t/find-by-compared-date/114215/1 "2007-09-10T01:54:01Z")

</div>

I how to find an object by an exact relative date, such as:

Model.find(:date =\> 2.days.ago)

How do I find an object with a :date of at least two days ago or at most  
two days ago?

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [September 10, 2007, 6:52am UTC](https://www.ruby-forum.com/t/find-by-compared-date/114215/2 "2007-09-10T06:52:59Z")

</div>

Peter M. wrote:

> I how to find an object by an exact relative date, such as:
> 
> Model.find(:date =\> 2.days.ago)
> 
> How do I find an object with a :date of at least two days ago or at most  
> two days ago?

Model.find(:conditions =\> [‘date \>= ?’, 2.days.ago])

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [September 10, 2007, 7:20am UTC](https://www.ruby-forum.com/t/find-by-compared-date/114215/3 "2007-09-10T07:20:03Z")

</div>

Keynan P. wrote:

> Model.find(:conditions =\> [‘date \>= ?’, 2.days.ago])

Thanks for your response Kenyan. I got this code to work for the find  
method:

Model.find(:first, :conditions =\> [‘date \<= ?’, 2.days.ago])

Any idea how I might get this to work with the ‘.exists?’ method?

Thanks Again,

Peter

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [September 11, 2007, 2:27am UTC](https://www.ruby-forum.com/t/find-by-compared-date/114215/4 "2007-09-11T02:27:41Z")

</div>

This is what i will use for the exist method:

Model.exists?([“date \<= ?”,2.days.ago])

Thanks Again,

Peter
