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, <<SNIP ATTRIBUTES>> 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 DESC
Even 1.minute.ago returns all posts. If flipping > with < returns 0
results. Grrr. Thanks in advance!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Taylor Strait 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!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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.> > This returns all posts. Dev log shows: > > SELECT posts.`id` AS t0_r0, <<SNIP ATTRIBUTES>> 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 DESC > > Even 1.minute.ago returns all posts. If flipping > with < returns 0 > results. Grrr. Thanks in advance! > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---