Rails ActiveRecord-如何在两个日期之间获取记录 [英] Rails ActiveRecord - how to fetch records between two dates
本文介绍了Rails ActiveRecord-如何在两个日期之间获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中有两个日期列- from_date
和 to_date
。
I have in the database two date columns - from_date
and to_date
.
示例:
-
from_date
: 2012 -09-10 -
to_date
: 2012-09-30 -
今天
: 2012-09-13
from_date
: 2012-09-10to_date
: 2012-09-30today
: 2012-09-13
如果今天
的日期在 from_date
和截止日期
。在SQL查询中该怎么做?
I would need to fetch all records, if today
's date is between from_date
and to_date
. How to do that in SQL query?
如果我已经加载了相应的记录,我可以很容易地决定,今天的日期是否在 from_date
和 to_date
,但我不知道如何从数据库中直接获取这些记录。
If I have loaded the respective record, I can easily decide, if today's date is between from_date
and to_date
, but I don't know, how to fetch straight those record from database.
推荐答案
data = ModelName.where("today >= from_date AND today <= to_date")
这篇关于Rails ActiveRecord-如何在两个日期之间获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文