My problem is when user selects same dates, query below returns empty array. Instead when user selects same dates, it has to show users created at that date. Any help will be appreciated.
User.where("created_at >= ? and created_at =< ?", params[:from].to_date, params[:to].to_date)
You are probably using DATETIME database columns. The problem is that the user selects “from” as (for example) 2011-07-09 and for the comparison the database translates that to “2011-07-09 00:00:00” and if the user selects the same day twice, there will probably be no results (unless they were exactly created at “2011-07-09 00:00:00”). To fix this, just do
before making the actual database search call. And use to_date instead of params[:to].to_date