Home>

As shown below, I am using Time.now.all_day to search for the corresponding data today, but what I want to do is get created_at and search for data with the same date as that date. ..

* If i search today, you will not be hit the next day. If i normally search with .creatd_at, it will be included in the search conditions until the time, and you will not be caught in the search.

@hoge = Score.where (created_at: Time.now.all_day)


The data that is the basis of the search is written as follows.

@play_date = Score.where (created_at: params [round_id]). first
<% = @ play_day.created_at.strftime ('% Y /% m /% d')%>


When I display the in view, the date can be output without any problem, but I don't know how to include this in the search conditions.

  • Answer # 1

    play_date = Score.where (round_id: params [: round_id]). first
    @ou = Score.where (created_at: play_date.created_at.in_time_zone.all_day) .where (course: params [: course]). where.not (hole_score: nil) .group (: round_id) .select ("round_id, sum" (hole_score) as overunder "). order ("overunder")