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

···

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

what is 1.day ?

···

On Wed, Apr 28, 2010 at 5:09 PM, -- -- <yannick@sente.ch> 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"

p 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"

compare

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

···

On Wed, Apr 28, 2010 at 5:09 PM, -- -- <yannick@sente.ch> 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"

botp 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 !

···

On Wed, Apr 28, 2010 at 5:09 PM, -- -- <yannick@sente.ch> wrote:

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