Learn and Learn

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

Ruby – Get Today or Current Date – today Method with Examples

The today method creates the date object from current date or today date in Ruby language. To get the today date, use Date.today method.

today Date Method in Ruby

today method exists in Standard Date Library of Ruby. The purpose of this method is to create the date object indicating the present day.

 

Syntax of the today Date Method in Ruby

In date, the syntax of today method is:

 

Return Value of today Method

today method will return the date object indicating the present day.

 

Get current / today Date in Ruby


Output
2015-07-27

 

Add Day in Current date in Ruby

Add days in the present date.


Output
2015-08-01

Output
2015-08-01

 

Subtract Day from Current date in Ruby

Subtract days from the present date.


Output
2015-07-22

Output
2017-07-22

 

Convert date into string


Output
“2015-07-27”

 

How to Get Day and Day Names in Ruby?


Output
4
Thursday

 

Get the Day Names with Index Number in Ruby


Output

Sunday
0
Monday
1
Tuesday
2
Wednesday
3
Thursday
4
Friday
5
Saturday
6

 

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