I\'m trying to search a model for any dates equal to a specific date while omitting the timestamp. In Rails I could simply execute this as DateTime.to_date == somedate
I would do something like...
someday = Date.today
Foo.where( :created_at => (someday)..(someday + 1.day) )
This would capture all created_at
dates between midnight on someday
and someday + 1
. This is inclusive (so it would include a Foo created bang on midnight on the +1 day) but may be 'just good enough' for your needs without messing with timestamps.
For niceness, I would wrap it up as a scope
scope :on_day, ( lambda do |someday|
where( :created_at => (someday)..(someday + 1.day) )
end )
So
Foo.on_day( Date.yesterday ).count
is nicely readable.