Find all in datetime with only date
When you store your dates as DateTimes, but are given only a date, use this named scope to select all items on a given date. Could probably be written to accept multiple dates as well.
View as text
named_scope :for_date, lambda { |date|
from = DateTime.parse "#{date} 12:00 AM"
to = DateTime.parse "#{date} 11:59:59 PM"
{
:conditions => ["datetime BETWEEN ? AND ?", from, to]
}
}
#sample use
tours = Tour.for_date(Date.today).all