문제

I am trying to attribute the time param with .to_date to generate the proper comparison

Organization.find(1140).events.all(:conditions => ["time < ?", Time.now.beginning_of_day]).blank?

How would I do that? I tried this :

Organization.find(1140).events.all(:conditions => [time.to_date < ?, Time.now.beginning_of_day]).blank?

And that's a big fail :D

도움이 되었습니까?

해결책

You can do something like this:

Organization.find(1140).events.all(:conditions => ["DATE(time) < ?", Date.today]).blank?

DATE() is a mysql function to parse the given value to Date format. And if you want to compare dates you should use Date.today instead of Time.now.beginning_of_day, it's much shorter and more readable.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top