Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Ruby – Find Next Month – next_month Method with Examples

In Ruby next_month is used to get one month ahead of the month given in a code. For example, if in your code, you have entered the fourth month and with the help of the next_month method, you will find the fifth month of that particular year. You can also get the desired month from the given code with the help of this method of Ruby.

Syntax of next_month Method in Ruby

Parameter of next_month Method in Ruby

x – where x is any valid date object such as 2016, 5, 10.
This parameter is required.

Error Handling of next_month Method in Ruby

If the x parameter is not a valid date object the next_month method will return an error and it could be due to the wrong format of the date in a code or the use of zero.

Return Value of next_month Method in Ruby

next_month method will return one month ahead of the month given in a code. You can also get desired month by using this method of Ruby.

Ruby next_month Method Example


Output:
2016,6,10

Ruby Different Methods of next_month


Output:
2014-06-15T10:22:55+00:00
2014-07-15T10:22:55+00:00

How to Print Next Month from Current Month in Ruby?


Output:
2014-12-15
2015-03-15

LearnAndLearn.com © 2018 - All rights reserved