Rails Console-查找在哪里创建的=某一天[英] Rails Console - Find where created at = certain day

本文是小编为大家收集整理的关于Rails Console-查找在哪里创建的=某一天的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

使用Ruby On Rails Console,是否可以查询数据库中的所有记录?

之类的东西
date = "january 5 2013"
users = User.find(:all, :conditions => {:created_at => date})

推荐答案

您可以这样做:

date = Date.parse('january 5 2013')
users = User.where(created_at: date.midnight..date.end_of_day)

其他推荐答案

尝试这个,

User.where("Date(updated_at) = ?", "2018-02-9")

其他推荐答案

您也可以做到

User.where("created_at::date = ?", "january 5 2013".to_date)

本文地址:https://www.itbaoku.cn/post/597655.html

问题描述

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"
users = User.find(:all, :conditions => {:created_at => date})

推荐答案

You can do it like this:

date = Date.parse('january 5 2013')
users = User.where(created_at: date.midnight..date.end_of_day)

其他推荐答案

Try this,

User.where("Date(updated_at) = ?", "2018-02-9")

其他推荐答案

You can also do it like

User.where("created_at::date = ?", "january 5 2013".to_date)