From: Arti Singh on
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
--
Posted via http://www.ruby-forum.com/.

From: AMILIN Aurélien on
Try :
Date.parse("Thu Aug 05 15:00:36 2010")
or
DateTime.parse("Thu Aug 05 15:00:36 2010") if you want to have access to
hours and minuites

Aurélien AMILIN
http://github.com/holinnn/


Le 06/08/2010 16:45, Arti Singh a écrit :
> 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

From: Siep Korteling on
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
--
Posted via http://www.ruby-forum.com/.

From: Gianfranco Bozzetti on
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: #<Date: 4910827/2,0,2299161>
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/.