I have two date columns – from_date
and to_date
in a database table.
Example:
from_date
: 2012-09-10to_date
: 2012-09-30today
: 2012-09-13
I need to fetch all records, if today
‘s date is between from_date
and to_date
. How do I do that with a SQL query?
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 those records straight from the database table.
Advertisement
Answer
data = ModelName.where("today >= from_date AND today <= to_date")