7stud -- wrote:
> Heesob Park wrote:
>> Hi,
>> 
>> Clement Ow wrote:
>>> Clement Ow wrote:
>>>> 
>>>>>   puts "I don't want to delete this file"
>>>>> end
>>>> 
>>>> Hi, thanks for that, did'nt know you can do it this way ;)
>>>> However, I have 2 formats, one yyyymmdd and the other just ddmmyyyy(w/o
>>>> any dashes). Unfortunately Parsedate cannot be used for ddmmyyyy. Only
>>>> yyyymmdd can work. Any ideas?
>>> 
>>> or is there any way that we can convert something like ddmmyyyy to 
>>> yyyymmdd so that it'll work when we use Date or parsedate to parse dates 
>>> in order to not raise an invalid date error?
>> 
>> 
>> [sidns@ns ~]$ irb
>> irb(main):001:0> require 'date'
>> => true
>> irb(main):002:0> Date.strptime('20102008',"%d%m%Y").to_s
>> => "2008-10-20"
>> irb(main):003:0> Date.strptime('20081020',"%Y%m%d").to_s
>> => "2008-10-20"
>> 
> 
> 
> $ irb
> irb(main):001:0> require 'date'
> => true
> irb(main):002:0> Date.strptime("20081020", "%Y%m%d").to_s
> ArgumentError: invalid date
>         from /usr/lib/ruby/1.8/date.rb:650:in `new_with_hash'
>         from /usr/lib/ruby/1.8/date.rb:675:in `strptime'
>         from (irb):2

hmmm. i even tried in irb whenever i use parse, it gives me an error:

Date.strptime('20081020',"%Y%m%d")
undefined method `strptime' for Date:Class (NoMethodError)

Date.parse('20081020',"%Y%m%d").to_s
undefined method `parse' for DateTime:Class (NoMethodError)
-- 
Posted via http://www.ruby-forum.com/.