Add one month or one year to a date

Hi,

I need to be able to add one month or in some cases on eyear to a Date.

Does anyone know of any easy ways of doing this?

thanks
scott

Yo!

Try:

@date_object = ‘12-02-2002’.to_date
@date_object_one_year_later = @date_object + 365

Ciao

Gustav P.
[email protected]
itsdEx.com

now = Time.now
=> Fri Jul 28 10:56:44 Eastern Standard Time 2006

now.next_month
=> Mon Aug 28 10:56:44 Eastern Standard Time 2006

now.next_year
=> Sat Jul 28 10:56:44 Eastern Standard Time 2007

Well, doesn’t get any easier than that!


From: [email protected]
[mailto:[email protected]] On Behalf Of Jeremiah
Peschka
Sent: Friday, July 28, 2006 10:57 AM
To: [email protected]
Subject: Re: [Rails] add one month or one year to a date

now = Time.now
=> Fri Jul 28 10:56:44 Eastern Standard Time 2006

now.next_month
=> Mon Aug 28 10:56:44 Eastern Standard Time 2006

now.next_year
=> Sat Jul 28 10:56:44 Eastern Standard Time 2007

On 7/28/06, dave [email protected] wrote:

Hi,

I need to be able to add one month or in some cases on eyear to a Date.

Does anyone know of any easy ways of doing this?

thanks
scott


Posted via http://www.ruby-forum.com/.

A lot of these are documented in the Time class, there are some great
methods in there like Time.at_beginning_of_day,
Time.at_beginning_of_month,
Time.seconds_since_midnight, etc,etc,etc

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs