Limiting query with created_at?

I have no idea why this isn’t working but maybe a new set of eyes can
help. I want to only collect posts from yesterday:

Post.find( :all,
           :conditions => "posts.created_at > #{(1.day.ago).to_i}",
           :order => "posts.created_at DESC",
           :include => :person)

This returns all posts. Dev log shows:

SELECT posts.id AS t0_r0, <> FROM posts LEFT OUTER
JOIN people ON people.id = posts.person_id WHERE (is_deleted = false AND
posts.created_at > 1173306785) ORDER BY posts.created_at DESCe

Even 1.minute.ago returns all posts. If flipping > with < returns 0
results. Grrr. Thanks in advance!

Taylor S. wrote:

I have no idea why this isn’t working but maybe a new set of eyes can
help. I want to only collect posts from yesterday:

Post.find( :all,
           :conditions => "posts.created_at > #{(1.day.ago).to_i}",

I though all databases only treated dates as formatted strings. Try
this:

            :conditions => "posts.created_at > '#{1.day.ago.to_s 

:db}'",

After that guess, I don’t know how a database will handle date
inequalities!


Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!

I have no idea why this isn’t working but maybe a new set of eyes can
help. I want to only collect posts from yesterday:

Post.find( :all,
:conditions => “posts.created_at > #{(1.day.ago).to_i}”,
:order => “posts.created_at DESC”,
:include => :person)

Let Rails convert the time into the format your database expects…

:conditions => [“posts.created_at > ?”, 1.day.ago]

Otherwise you’re going to need to format that time so your database
understands it.

Let Rails convert the time into the format your database expects…

:conditions => [“posts.created_at > ?”, 1.day.ago]

Otherwise you’re going to need to format that time so your database
understands it.

That worked great. Thanks!