Get yesterday's date

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).

Answers


(Date.today-1).strftime('%Y-%m-%d')

Would be a non rails-specific way.


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

Need Your Help

SQL 2008 setting compatibility level

sql sql-server database sql-server-2008

When I try to add a data-base in SQL Server 2008 (Right clicking on Databases folder->New Database) the only compatibility options given to me in the options tab are 70, 80, and 90.

HTML cell containing css scrollbars — how can I get rid of the padding?

html css cellpadding

I have an HTML table, where each cell contains a large amount of data. I would like each cell to be individually scrollable (sort of like "panes"), so I created a CSS class that includes the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.