Reputation: 5603
Using Rails 4.0, I need to return a date for the first of the current month in the following format:
2014-01-01
Date.today.at_beginning_of_month
gives me this:
Wed, 01 Jan 2014
How can I format the date to the above?
Upvotes: 0
Views: 426
Reputation: 20935
Date.today.at_beginning_of_month.strftime("%F")
See: http://www.ruby-doc.org/core-2.0/Time.html#method-i-strftime for various other date and time formats.
%F => 2007-11-19 Calendar date (extended)
Upvotes: 2