Skip to content

Instantly share code, notes, and snippets.

@stefanpenner
Created July 12, 2009 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanpenner/145777 to your computer and use it in GitHub Desktop.
Save stefanpenner/145777 to your computer and use it in GitHub Desktop.
named_scope :bill_on, lambda { |*args|
date_to_bill = args[0]||Time.now.to_date
if date_to_bill.day < 27
{ :conditions => "DAY(billing_date) = #{date_to_bill.day}" }
else
offset = date_to_bill.end_of_month.day - date_to_bill.day
{ :conditions => "( DAY(LAST_DAY(CURRENT_DATE))-DAY(billing_date) ) = #{offset}" }
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment