xxxxxxxxxx
# A simple trick is to use a BETWEEN clause, achievable without writing pure SQL and just by using ActiveRecord:
Count.where(created_at: Date.yesterday.beginning_of_day..Date.yesterday.end_of_day)
# It will translate to the following SQL:
WHERE ("counts"."created_at" BETWEEN '2019-01-02 00:00:00.000000' AND '2019-01-02 23:59:59.999999')