试图搜索出现的电影的发布日期大于今天的日期
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')
Run Code Online (Sandbox Code Playgroud) 在Mac Snow leopard上使用Ruby 1.9.2和Rail 3
ruby-1.9.2-p290 :001 > Date.today
=> Sun, 25 Sep 2011
ruby-1.9.2-p290 :002 > Date.tomorrow
=> Tue, 27 Sep 2011
Run Code Online (Sandbox Code Playgroud)
ruby日期类可能有问题,或者这与我安装ruby的方式有关?
编辑:
ruby-1.9.2-p290 :039 > Date.current
=> Mon, 26 Sep 2011
ruby-1.9.2-p290 :040 > DateTime.now
=> Sun, 25 Sep 2011 20:47:01 -0500
Run Code Online (Sandbox Code Playgroud)
好吧所以rails Date类看起来有点儿麻烦.DateTime类似乎工作正常.感谢derp和Adam