views:

103

answers:

0

When I create a SQL Time column I get a pure time, ie. no date. But when I use the Ruby Time class I get a date as well. The problem is when do a 'find' the generated SQL includes a date and I seem to be getting weird results.

The 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

The 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 SQL generated includes a date, could this be why I'm getting odd results, for example no record returned when there is a schedule for the given time? However if the column is a pure time column should MySQL not ignore the date part?