Rails ActiveRecord Find / Search by Date

后端 未结 3 1352
醉话见心
醉话见心 2020-12-31 22:22

I am trying to find records by \'created_at\' date - the database column type is \'datetime\' and I am using the UI DatePicker from jQuery

my url look like this: \"

3条回答
  •  情话喂你
    2020-12-31 22:49

    selected_date = Date.parse(params[:selected_date])
    # This will look for records on the given date between 00:00:00 and 23:59:59
    sh = SupportHistory.where(
           :created_at => selected_date.beginning_of_day..selected_date.end_of_day)
    

    Time Zones may be a concern you need to look into, but this should work if all your times are in the same time zone.

提交回复
热议问题