Reputation: 1658
How I can get the next year in Rails?
I need to get only the year, without the date.
When I do 1.year.from_now
it returns a full date, not just the year.
Upvotes: 1
Views: 2582
Reputation: 114138
today
's date:
require 'date'
Date.today
#=> #<Date: 2018-01-02 ...>
This day next_year
:
Date.today.next_year
#=> #<Date: 2019-01-02 ...>
And finally its year
:
Date.today.next_year.year
#=> 2019
Upvotes: 1
Reputation: 375
Try these
Time.now.year + 1
output will be
2019
As suggest by @sschmeck you can try these also to get only next year
Time.now.year.succ
Upvotes: 5
Reputation: 1639
There are several options to do this. But using your format, we can do it like this:
1.year.from_now.year
Upvotes: 6