Rails Console - Find where created at = certain day

后端 未结 5 606
醉话见心
醉话见心 2021-02-01 03:48

With Ruby on Rails console, is it possible to query the database for all records created on a certain day?

something like

date = \"january 5 2013\"
user         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 04:32

    If you see the follow link Don't use BETWEEN (especially with timestamps) You will note that you can have problems.

    Instead you can use

    users = User.where('created_at >= ? and created_at <=?', date.midnight, date.end_of_day)
    
    
    
    "SELECT \"users\".* FROM \"users\" WHERE (created_at >= '2018-05-17 07:00:00' and created_at <='2018-05-18 06:59:59.999999')"
    

提交回复
热议问题