【问题标题】:rails howto compare datetime?rails如何比较日期时间?
【发布时间】:2010-05-13 18:04:36
【问题描述】:

我的 sqLite 数据库中有游戏,属性为starting_date(t.date:starting_date)。 我想知道所有已经开始的游戏,所以我使用这行代码:

Game.find :all,:conditions=>"starting_date <= #{Date.today}"
Game.find_by_sql("SELECT * FROM "games" WHERE (created_at < 2010-05-13)")

结果是 nill,即使我知道我已经有类似这样的游戏开始了:

#<Game id: 1, team_1_id: 2, team_2_id: 1, status: 2, team_1_points: nil, team_2_points:    nil, starting_date: "2010-05-05", winner: 1, sport: "football", country: nil, league: "calcio", created_at: "2010-04-07 00:09:21", updated_at: "2010-05-13 00:57:19">

我在这里做错了什么?

【问题讨论】:

    标签: sql ruby-on-rails activerecord


    【解决方案1】:
    Game.all(:conditions => ["starting_date <= ?", Date.today])
    

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      相关资源
      最近更新 更多