Learn and Learn

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

How to Parse Date in Ruby? – Examples & Explanation

The parse method describes the given representation of date and time and returns the described elements. To find out the parse of the any given date in Ruby, date.parse() method is used.

date.parse() Method in Ruby

date.parse() method exists in Standard Date Library of Ruby. The purpose of this method is to provide an explanation for any given date.

 

Syntax of the parse Method in Ruby

In date, the syntax of parse method is:

 

Parameter of date.parse() Method in Ruby

The parameter x is any valid date string that could be converted into a date object. This parameter is required.Note: If the x parameter is not a date object, date.parse() method will return an error.

 

Return Value of date.parse()

date.parse method will return the parsed elements of any given date.

 

Parse any Date in Ruby


Output
2015-09-13

 

Various Formats of date.parse() Method in Ruby


Output
2011-12-23

 


Output
2015-08-23

 

Explaining Date and Time with date.parse() Method.


Output
2015-08-23T12:44:05+00:00

 

Adding Days in Current Date with date.parse() Method


Output
2015-05-01

 

Subtracting Days from Current Date with date.parse() Method

Subtracting days from the current date.


Output
2015-04-21

 

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