Learn and Learn

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

Ruby – Find Month Number – month Method – Examples & Explanation

month method returns the number of a month from 1 (Jan) to 12 (Dec). The month method used to get the number of a month from a particular given code in Ruby. January represents as 1 and December presents 12. month is a part of Date Library in Ruby.

Syntax of month Method in Ruby

The syntax of month Method in Ruby Language is:

In month method the expression is ued as mon in the code.

 

Parameters of month Method in Ruby

x – Where x is any valid date object. This parameter is required.

 

Error Handling

If the x parameter is not a date object month method returns an error.If the date is not valid or it is zero then the month method will show an error.

 

Return Value of month Method in Ruby

month method will return the number of a month from 1 (Jan) to 12 (Dec).

 

Ruby – Use of month


Output:
5

How to Get the Number of a Month with month Method in Ruby?


Output:
12

Ruby month Method Explanation


Output:
9

Loading...
LearnAndLearn.com © 2018 - All rights reserved