fenec
fenec

Reputation: 5806

rails howto compare datetime?

i have games in my sqLite DB with the attribute starting_date( t.date :starting_date). i would like to know all the games that have alreday started so i am using this lines of code:

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

the result is nill,even though i know that i have games that have already started like this one :

#<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">

what am i doing wrong here?

Upvotes: 0

Views: 1506

Answers (1)

Ju Nogueira
Ju Nogueira

Reputation: 8461

Game.all(:conditions => ["starting_date <= ?", Date.today])

Upvotes: 3

Related Questions