Ruby-on-rails – How to get record created today by rails activerecord

daterails-activerecordruby-on-rails

How should I write the conditional statement for when I want to get all the records which were created today?

Best Answer

Post.where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day)

PS: This answer has been modified as answer by Harish Shetty was better than mine. As my answer is accepted one. I have updated this answer for community support