Change string to date error

i get the following error. wonder why

irb(main):068:0> @@config[“date”]
=> “27/12/2007”
irb(main):069:0> Time.parse(@@config[“date”])
ArgumentError: argument out of range
from e:/ruby/lib/ruby/1.8/time.rb:184:in local' from e:/ruby/lib/ruby/1.8/time.rb:184:inmake_time’
from e:/ruby/lib/ruby/1.8/time.rb:243:in `parse’
from (irb):69
from :0
irb(main):070:0>

On Thu, 2007-12-27 at 22:39 +0900, Junkone wrote:

    from :0

irb(main):070:0>

You have the month and day swapped - there’s no 27th month in a year:

$ irb
irb(main):001:0> require ‘time’
=> true
irb(main):002:0> Time.parse(‘27/12/2007’)
ArgumentError: argument out of range
from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:in local' from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:inmake_time’
from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:243:in `parse’
from (irb):2
irb(main):003:0> Time.parse(‘12/27/2007’)
=> Thu Dec 27 00:00:00 -0800 2007
irb(main):004:0>

HTH,

Felix

On Dec 27, 9:06 am, fw [email protected] wrote:

    from (irb):69
    from /home/felix/ruby1.8.6/lib/ruby/1.8/time.rb:184:in `local'

Felix
i have a canadian layout and my regional settings on my computer is
set to dd/mm/yyyy. strange that ruby cannot get this one right. all my
office apps and my oracle and mysql databases now recognise this
format on my computer.

On Dec 27, 12:21 pm, Junkone [email protected] wrote:

ArgumentError: argument out of range
irb(main):001:0> require ‘time’
irb(main):004:0>

HTH,

Felix

i have a canadian layout and my regional settings on my computer is
set to dd/mm/yyyy. strange that ruby cannot get this one right. all my
office apps and my oracle and mysql databases now recognise this
format on my computer.

Here ya go, eh. :wink:

Time.parse(@@config[“date”].gsub(/(.?)/(.?)/(.*)/, ‘\2/\1/\3’))

Regards,
Jordan

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