Search code examples
sqlruby-on-rails-3

Rails where date is greater than given date query


Trying to search where movies coming out have a release date greater than today's date

 Movie.where('release > ?', Date.today)
ActiveRecord::StatementInvalid: Mysql::ParseError: You have an error in your SQL     syntax;    check the manual that corresponds to your MySQL server version for the right syntax to use near 'release > '2011-09-25')' at line 1: SELECT `movies`.* FROM `movies` WHERE (release > '2011-09-25')

Solution

  • Rails 3+ :

    Movie.where('release > ?', DateTime.now)
    

    Pre Rails 3

    Movie.where(['release > ?', DateTime.now])