Comparing datetimes does not work
- by Koning Baard XIV
I'm creating a Rails application which uses MySQL. I have a table in my DB like this:
create_table "pastes", :force => true do |t|
t.string "title"
t.text "body"
t.string "syntax"
t.boolean "private"
t.datetime "expire"
t.string "password"
t.datetime "created_at"
t.datetime "updated_at"
end
I want to show only the non-expired pastes to people, so I do this:
@pastes = Paste.find(:all, :conditions => "expire < '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}'")
However, even that returns ALL pastes. Not just those that are not expired yet. Can anyone help me? Thanks
Oh, changing < to > returns no pastes, not even the non-expired ones :(