Never been to DZone Snippets before?

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

About this user

Zeke Sikelianos

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Find all rows for a certain day; Count days between two dates

   1  
   2  # Find all rows created on a certain day; Rails apparently has a built-in :db string format
   3  self.find(:all, :conditions => ["created_at >= ? AND created_at <= ?", day.beginning_of_day.to_s(:db), day.end_of_day.to_s(:db)])
   4  
   5  # Find number of days between two dates
   6  def days_between_dates(first, last)
   7    (YMD(last) - YMD(first))
   8  end
   9  
  10  def YMD(date)
  11    date.to_date.to_s.gsub("-", "").to_i
  12  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS