I am trying to query a shopping table in my rails database (Postgres) and I want to query time ranges.
For example, I would like to know how many purchases were made between 14:00 and 15:00 on all dates.
There is a column in this table created_at, but I don’t see how to do it without searching for a specific date.
I tried:
Purchases.where("created_at BETWEEN ? and ?", Time.now - 1.hour, Time.now)
But it will ultimately just look for today's date with those times.
source
share