From: Ne Scripter Date: 2009-09-01T23:00:37+09:00 Subject: Re: Date & time validation Robert, I understand what you are doing here and I have looked at using this already however if I have a string 2009/09/01 12:22:36 it will be returned as true because the date format is correct, the string above will in fact be invalid because only a field consisting of yyyy/mm/dd is valid. Many thanks Stuart Robert Klemme wrote: > 2009/9/1 Ne Scripter : >> date1 = field[2] >> valid � �date of yyyy/mm/dd. The data being checked can be anything, so >> >> Any ideas on how to do this? I was looking a the docs for date and I am >> struggling to make head way at this stage. >> >> Thanks in advance! > > Just parse it into a Time instance: > > 15:32:29 ~$ irb19 -r time > Ruby version 1.9.1 > irb(main):001:0> Time.parse '2009/01/02' > => 2009-01-02 00:00:00 +0100 > irb(main):002:0> Time.parse '2009/20/02' > ArgumentError: argument out of range > from /opt/lib/ruby19/1.9.1/time.rb:202:in `local' > from /opt/lib/ruby19/1.9.1/time.rb:202:in `make_time' > from /opt/lib/ruby19/1.9.1/time.rb:261:in `parse' > from (irb):2 > from /opt/bin/irb19:12:in `
' > irb(main):003:0> > > Cheers > > robert -- Posted via http://www.ruby-forum.com/.