Adding days to date

Hello,

Does anyone know what the problem with the following code ???

Date.today.to_s
=> “2010-04-28”

(Date.today + 1.day).to_s
=> “2246-11-17”

(Date.today + 2.days).to_s
=> “2483-06-07”

Thanks in advance

On Wed, Apr 28, 2010 at 5:09 PM, – -- [email protected] wrote:

Does anyone know what the problem with the following code ???

Date.today.to_s
=> “2010-04-28”

(Date.today + 1.day).to_s
=> “2246-11-17”

(Date.today + 2.days).to_s
=> “2483-06-07”

what is 1.day ?

On Apr 28, 2010, at 02:09 , – -- wrote:

Hello,

Does anyone know what the problem with the following code ???

Date.today.to_s
=> “2010-04-28”

(Date.today + 1.day).to_s
=> “2246-11-17”

(Date.today + 2.days).to_s
=> “2483-06-07”

p 1.day

On Wed, Apr 28, 2010 at 5:09 PM, – -- [email protected] wrote:

Does anyone know what the problem with the following code ???

Date.today.to_s
=> “2010-04-28”

(Date.today + 1.day).to_s
=> “2246-11-17”

(Date.today + 2.days).to_s
=> “2483-06-07”

compare

Date.today + 1
Date.today + 2
Time.now + 1.day
Time.now + 2.day

botp wrote:

On Wed, Apr 28, 2010 at 5:09 PM, – -- [email protected] wrote:

Does anyone know what the problem with the following code ???

Date.today.to_s
=> “2010-04-28”

(Date.today + 1.day).to_s
=> “2246-11-17”

(Date.today + 2.days).to_s
=> “2483-06-07”

compare

Date.today + 1
Date.today + 2
Time.now + 1.day
Time.now + 2.day

1.day
=> 86400

(Date.today + 1).to_s
=> “2010-04-29”

(Time.now + 1.day).to_s
=> “Thu Apr 29 09:32:28 +0000 2010”

1.day is in seconds, so it adds 86400 days instead of 1…

Thank you for your replies !

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