Reputation: 741
I want to get all the records from the database which are create_at today. But when I do
Model.where('DATE(created_at) = ?',Date.today)
it returns only the last record that is created today. I have 3 records with created_at
2015-03-03 11:38:31
2015-03-03 11:59:00
2015-03-03 11:33:04
. But it returns only the record with '2015-03-03 11:38:31' this created_at date.
Also referred How to delete all records created today?, Getting all rows created today. I want to know why is this happening? Also tried
Model.where("DATE(created_at) = ?",Date.today)
and
Tracking::TrackingLogin.where("created_at >= ?", Time.zone.now.beginning_of_day)
Please someone explain what is happening in my code?
Upvotes: 3
Views: 5649
Reputation: 1
Model.where("created_at >= ?", Time.zone.now.beginning_of_day)
Model = your model name
(i.e,. User.where("created_at >= ?", Time.zone.now.beginning_of_day))
Upvotes: 0
Reputation: 1468
Try the following:
Model.where("created_at >= ?", Time.zone.now.beginning_of_day)
Upvotes: 13