Created
August 4, 2009 13:20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
range = "created_at #{(12.months.ago.to_date..Date.today).to_s(:db)}" | |
# .to_s(:db) is a helper to transform a date-range into SQL condition clause | |
# ex. above: => "created_at BETWEEN '2006-01-05' AND '2007-01-05'" | |
@users = User.count(:all, :conditions => range, :group => "DATE_FORMAT(created_at, '%Y-%m')", :order =>"created_at ASC") | |
# - count all users, whose created_at timestamp falls within the range specified above | |
# - group users by 'Year-Month', and count the number of occurences within each group | |
# ex. result: | |
# count | date | |
# --------------- | |
# 2 | 2005-10 | |
# 24 | 2005-11 | |
# 32 | 2005-12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment