Mellon
Mellon

Reputation: 38902

a question on ActiveRecord query

in my model, I use the where statement to query the DB table:

where(:date=>start_date..end_date)

It is obvious that I would like to get all records between start_date and end_date in the date column. The start_date and end_date are Date type values.

Based on this query, I get the results from the table BUT not exactly everything.

The data match the date value of "end_date" is not return. That's this query exclude the data on end_date, it only get the results from start_date to end_date-1.day, how to get rid of this? I want to use this query to return the data with end_date>=date>=start_date

Upvotes: 0

Views: 55

Answers (1)

gertas
gertas

Reputation: 17145

Try: where('date BETWEEN ? AND ?', start_date, end_date)

Upvotes: 1

Related Questions