Trip
Trip

Reputation: 27114

Proper syntax in RoR for time in datetime comparison

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

Upvotes: 0

Views: 107

Answers (1)

jigfox
jigfox

Reputation: 18175

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.

Upvotes: 1

Related Questions