Ruby – Find Month Day Number – mday Method with Examples

mday method is used to return the day of the month which are starting from 1 to maximum 31. mday is a part of date Library in Ruby.

Syntax of mday Method in Ruby

The syntax of mday Method in Ruby Language is:

Date.new(x).mday

 

Parameter of mday Method in Ruby

x – Where x is any valid date object from which the number of the day of that month is required. This parameter is required.

 

Error Handling

If the x parameter is not a valid date object mday method returns an error.

 

Return Value of mday Method in Ruby

mday method will return the number of the day in a particular month.

 

How to Get the Number of the Day in a Month in Ruby?

# import date library
require 'date'
x = Date.new(2016,12,13).mday
puts x

Output:
13

Ruby – Use of mday

# import date library
require 'date'
x = Date.new(2016,2,10).mday
puts x

Output:
10

Useful way of using mday in Ruby

# import date library
require 'date'
x = Date.new(2016,10,20).mday
puts x

Output:
20