How I can get yesterday's date?
Rails
For a date object you could use:
Date.yesterday
Or a time object:
1.day.ago
Ruby
Or outside of rails:
Date.today.prev_day
After trying 1.day.ago
and variants on it:
irb(main):005:0> 1.day.ago
NoMethodError: undefined method `day' for 1:Fixnum
if found that Date.today.prev_day
works for me:
irb(main):016:0> Date.today.prev_day
=> #<Date: 2013-04-09 ((2456392j,0s,0n),+0s,2299161j)>
Time.now - (3600 * 24) # or Time.now - 86400
or
require 'date'
Date.today.prev_day