From: Gianfranco Bozzetti Date: 2010-08-08T00:27:55+09:00 Subject: Re: Parse a Date From a String Siep Korteling wrote: > Arti Singh wrote: >> Help!! I get a float when I try to parse a date from a string. >> The date from the string is in the format "Thu Aug 05 15:00:36 2010" >> I try date_var="Thu Aug 05 15:00:36 2010" >> date_var.strptime("%a %b %d %I:%M:%S %Y") but I get a floating point >> variable > > The "%I" in your code should be a "%H" (24 hour clock) > > require 'date' > date_var = "Thu Aug 05 15:00:36 2010" > date = Date.strptime( date_var, "%a %b %d %H:%M:%S %Y" ) > p date > > hth, > > Siep p(obj) displays obj using its inspect method. To display the date use date.to_s as in; require 'date' date_var = "Thu Aug 05 15:00:36 2010" date = Date.strptime( date_var, "%a %b %d %H:%M:%S %Y" ) p date # displays: # p date.to_s # displays: "2010-08-05" note the double quotes puts date.to_s # displays: 2010-08-05 HTH gfb -- Posted via http://www.ruby-forum.com/.