Rails: find by day of week with timestamp
Posted
by Sleepycat
on Stack Overflow
See other posts from Stack Overflow
or by Sleepycat
Published on 2010-03-29T02:22:19Z
Indexed on
2010/03/29
2:23 UTC
Read the original article
Hit count: 444
ruby-on-rails
|best-practices
I need to grab the records for same day of the week for the preceeding X days of the week. There must be a better way to do it than this:
Transaction.find_by_sql "select * from transactions where EXTRACT(DOW from date) = 1 and organisation_id = 4 order by date desc limit 7"
It gets me what I need but is Postgres specific and not very "Rails-y". Date is a timestamp. Anyone got suggestions?
© Stack Overflow or respective owner