What am I doing incorrectly that is giving me a blank array from this command?
Item.where(:load_date => Date.today + 2)
Here is my Rails Console:
.9.3-p194 :024 > Item.first.load_date
Item Load (0.3ms) SELECT "items".* FROM "items" LIMIT 1
=> Fri, 24 May 2013
1.9.3-p194 :025 > Item.where(:load_date => Date.today + 2)
Item Load (0.5ms) SELECT "items".* FROM "items" WHERE "items"."load_date" = '2013-05-24'
=> []
1.9.3-p194 :026 > Item.first.load_date == Date.today + 2
Item Load (0.3ms) SELECT "items".* FROM "items" LIMIT 1
=> true
Item Model:
...
# load_date :date
...
class Item < ActiveRecord::Base
attr_accessible :bt_num, :dept, :formula, :item_code, :load_date, :prod_comments, :qc_comments, :qc_tech, :qty_in_kg, :qty_in_liters, :rm_ok_by, :series, :status, :time_to_produce, :vat
...
Try these
Item.where(:load_date => (Date.today + 2).strftime)
or
Item.where("Date(load_date) =?", (Date.today + 2).strftime)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With