Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top