Hey all,
I have a model Post with a datetime posted_on attribute.
What’s the best way to find all the posts that were posted x days,
let’s say 5 days ago?
thanx in advance
Pat
Hey all,
I have a model Post with a datetime posted_on attribute.
What’s the best way to find all the posts that were posted x days,
let’s say 5 days ago?
thanx in advance
Pat
recent_posts = Post.find(:all,
:conditions => “date_posted >
#{5.days.ago.to_s(:db)}”)
oops…
recent_posts = Post.find(:all, :conditions => “posted_on >
#{5.days.ago.to_s(:db)}”)
jdswift wrote:
recent_posts = Post.find(:all, :conditions => “posted_on >
#{5.days.ago.to_s(:db)}”)
Don’t you need more quotes?
Which of these would work?
:conditions => [‘posted_on > ?’, 5.days.ago.to_s(:db)]
:conditions => [‘posted_on > ?’, 5.days.ago]
–
Phlip
Redirecting... ← NOT a blog!!!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs