DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Find All Rows For A Certain Day; Count Days Between Two Dates
# Find all rows created on a certain day; Rails apparently has a built-in :db string format
self.find(:all, :conditions => ["created_at >= ? AND created_at <= ?", day.beginning_of_day.to_s(:db), day.end_of_day.to_s(:db)])
# Find number of days between two dates
def days_between_dates(first, last)
(YMD(last) - YMD(first))
end
def YMD(date)
date.to_date.to_s.gsub("-", "").to_i
end





Comments
Snippets Manager replied on Tue, 2009/08/04 - 4:35pm
Snippets Manager replied on Tue, 2009/08/04 - 4:35pm