Rails ActiveRecord Query Date Range

Viewed 43627

I'm trying to use the following line in my controller to capture all tasks due less than a week from the current date:

@due_this_week = current_user.tasks.where(due_date: Date.today..1.week.from_now)

For some reason it's not finding any results even I know I have tasks due within four and six days. This is the only instance variable using a range query. I have another one that works fine to find overdue tasks:

@overdue = current_user.tasks.where("due_date <= ?", Date.today)

What am I missing?

2 Answers

Should be:

@due_this_week = current_user.tasks.where(due_date: 1.week.ago..Date.today)
Related