When I create the SQL Time column, I get pure time, i.e. without date. But when I use the Ruby Time class, I get the date as well. The problem is when the “find” generated SQL includes the date, and I seem to get weird results.
Table
start_date: time
end_time: time
day_of_week: string
Activerecord
def self.now_playing
self.find(:first, :conditions => ['day_of_week = ? AND end_time > ? AND start_time < ?', Time.now.strftime('%A'), Time.now, Time.now])
end
SQL
SELECT * FROM `schedules` WHERE (day_of_week = 'Saturday' AND end_time > '2009-06-20 10:19:59' AND start_time < '2009-06-20 10:19:59') LIMIT 1
The generated SQL contains the date, maybe that's why I get odd results, for example, the record is not returned when there is a schedule at the moment? However, if the column is a pure time column, if MySQL does not ignore the date part?
source
share