问题
I'm trying to get a page to display a list of all the records that are valid at the current time, so comparing the start and end time & date to the time at that current moment. This is the code I have at the moment:
def self.time
find_by_sql("SELECT *
FROM screens s
WHERE (s.starttime < CONVERT(varchar(30), GETDATE(), 114)) AND (s.finishtime > CONVERT(varchar(30), GETDATE(), 114))")
end
However I get this: ActiveRecord::StatementInvalid
I know my code isn't right.. I just don't quite know how to fix it?
回答1:
def self.time
find_by_sql("SELECT *
FROM screens s
WHERE (s.starttime < #{Time.now}) AND (s.finishtime > #{Time.now}")
end
来源:https://stackoverflow.com/questions/14212478/comparing-with-current-time-sql