How to obtain first day of next month in ruby?

You can do

require "active_support"

require "active_support/core_ext/date/calculations"
# || require "active_support/all"

Date.today.at_beginning_of_month
#=> Wed, 01 Dec 2010

Date.today.at_beginning_of_month.next_month
#=> Sat, 01 Jan 2011

Date.today.at_beginning_of_month.next_month.next_month
#=> Tue, 01 Feb 2011

And so on…

References

Rails guide 3.0 – 6.1.4 – ActiveSupport – How to Load Core Extensions
Rails guide 3.0 – 6.1.4 – ActiveSupport – Extensions to date

Leave a Comment