我希望能够在我的数据库中列出与在我的方法中创建的另一个事件相同的日期发生的任何“事件”。我想比较的列是'starts_at
‘,是一个DateTime
。如何比较事件发生的日期而不是日期和时间?
我需要将查询添加到其中调用:
events = Event.where(location_id: location.id)
我已经有了一个日期对象date
,我只是不知道如何才能得到数据库中已经存在的事件的日期部分?
它是否类似于日期(starts_at:)?
events = Event.where(location_id: location.id, date(starts_at:): date)
我正在使用sqlite数据库。
发布于 2016-04-09 02:52:44
检查这是否适用于您的DB:
events = Event.where(location_id: location.id).where("DATE(starts_at) = ?", date)
或者,按活动记录在日期时间上进行比较:
events = Event.where(location_id: location.id,starts_at: date.beginning_of_day..date.end_of_day)
https://stackoverflow.com/questions/36515578
复制相似问题