Rails query timestamp between two hours

后端 未结 3 1977
天涯浪人
天涯浪人 2021-01-07 05:33

I have a problem in Ruby on Rails, where I need to allow a user to set a two time columns, and then query all instances of that model that have the current time within the h

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 06:01

    You might be looking for something like

    Model.where("starts_at >= ? AND ends_at =< ?", Time.current, Time.current)

    Alternatively, you can use placeholder conditions to make the query more concise.

    Client.where("created_at >= :start_date AND created_at <= :end_date", {start_date: params[:start_date], end_date: params[:end_date]})

提交回复
热议问题