与当前时间SQL比较 [英] Comparing with current time SQL
本文介绍了与当前时间SQL比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图获取一个页面来显示当前时间有效的所有记录的列表,因此比较开始和结束时间&日期到当前时刻的时间。这是我现在的代码:
def self.time
find_by_sql(SELECT *
从屏幕s
WHERE(s.starttime end
但是我得到这个: ActiveRecord :: StatementInvalid
我知道我的代码不正确..我只是不知道如何解决它?
解决方案
def self.time
pre>
find_by_sql(SELECT *
FROM screens s
WHERE(s.starttime <#{Time.now})AND(s.finishtime>#{Time.now})
end
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?
解决方案def self.time find_by_sql("SELECT * FROM screens s WHERE (s.starttime < #{Time.now}) AND (s.finishtime > #{Time.now}") end
这篇关于与当前时间SQL比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文