Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Find All Rows For A Certain Day; Count Days Between Two Dates

DZone's Guide to

Find All Rows For A Certain Day; Count Days Between Two Dates

·
Free Resource

# 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
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}