From: Michael Libby Date: 2008-08-06T22:53:34+09:00 Subject: Re: is there a way to AutoParse a string to another type - e.g. if a Date format then date, else if integer than Integer etc ????? On Wed, Aug 6, 2008 at 12:50 AM, Greg Hauptmann wrote: > umm...Date parse doesn't seem to be that good, for example see below > >>> Loading development environment (Rails 2.1.0) >>> > ?> Date.parse("123", "%d/%m/%Y") > => Fri, 02 May 2008 >>> Date.parse("123", "%d/%m/%Y").class > => Date As far as I can tell, Date.parse doesn't really want a format string as the second argument. And Date.parse is working great in your example, it gave you a date corresponding to the 123rd day of this year. :) If you're not sure whether your input string is actually a date, you might be more interested in Date.strptime: irb(main):012:0> value = Date.strptime("123", "%d/%m/%y") rescue Integer("123") => 123 irb(main):013:0> value.class => Fixnum -Michael