This may be an obvious question but im new to ruby and I've spent ages trying to get yesterdays date for a cucumber test that checks a url that includes yesterday's date. for example: http://www.blah.co.uk/blah/blah/schedule/2011-11-28
I've created the following within my helper methods:
def Helper.get_date
Time.now.strftime('%Y-%m-%d') / 1.day
end
But it doesn’t like the /1.day or – 1.day or – 86400 (seconds).
You can use some of the methods in ActiveSupport (which will be included if you're in a Rails app) to do the following:
DateTime.yesterday.strftime('%Y-%m-%d')
EDIT: As it's a standard date format, you could also reference the standard directly:
DateTime.yesterday.iso8601
(Date.today-1).strftime('%Y-%m-%d')
Would be a non rails-specific way.
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