Peter Penzov
Peter Penzov

Reputation: 1658

Proper way to get next year from now

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

Answers (4)

Ritesh Ranjan
Ritesh Ranjan

Reputation: 1012

You can use this,

d = Time.now.year.next

Upvotes: 0

Stefan
Stefan

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

lg86
lg86

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

Nabin Paudyal
Nabin Paudyal

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

Related Questions