Comparing with current time SQL

[亡魂溺海] 提交于 2019-12-25 00:23:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!