Comparing datetimes does not work
Posted
by Koning Baard XIV
on Stack Overflow
See other posts from Stack Overflow
or by Koning Baard XIV
Published on 2010-04-24T17:50:54Z
Indexed on
2010/04/24
17:53 UTC
Read the original article
Hit count: 237
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 :(
© Stack Overflow or respective owner