Comparing times only, without dates?

后端 未结 8 1246
不知归路
不知归路 2021-01-31 16:30

I need to write a method that will check if Time.now is in between the open hours and the close hours of a shop.

The open and close hours are saved as a Tim

8条回答
  •  攒了一身酷
    2021-01-31 17:13

    You can compare only time in rails without date part like:--- Here post_review is table and we are getting only these record of post_review which are created_at between 10 am ---5pm in any date

    post_review.where("(created_at::time >= :start_time) AND (created_at::time <= :end_time)", 
        start_time: Time.parse("10 am").strftime("%r"),
        end_time:   Time.parse("5 pm").strftime("%r")
     )
    

提交回复
热议问题