Converting Date string to Time Object

Hi,

I have MySQL model with created_on specified as :date. This means that
the
day the record was created on is stored in the database as a string like
“2006-04-28”. I want to be able output a something like “5 days ago”.
From
looking in the API I’ve found “strftime” and
distance_of_time_in_words”.
Distance_of_time_in_words only accepts Time objects and integers, so I
guess
my question is how do I convert “news.send(“created_at”)” to either a
Time
object or a integer? I’ve tried a few things like
“news.send(“created_at”).to_i”
but nothing works.

I’m sure that there is probably some helper which will let me do this
but
I’m not sure what it is.

Any help will be greatly appreciated.

Chris

Try the to_time method

eg

news.created_at.to_time

----- Original Message -----
From: Chris Lloyd
To: [email protected]
Sent: Friday, July 14, 2006 8:47 AM
Subject: [Rails] Converting Date string to Time Object

Hi,

I have MySQL model with created_on specified as :date. This means that
the day the record was created on is stored in the database as a string
like “2006-04-28”. I want to be able output a something like “5 days
ago”. From looking in the API I’ve found " strftime" and
“distance_of_time_in_words”. Distance_of_time_in_words only accepts Time
objects and integers, so I guess my question is how do I convert "
news.send(“created_at”)" to either a Time object or a integer? I’ve
tried a few things like “news.send(“created_at”).to_i” but nothing
works.

I’m sure that there is probably some helper which will let me do this
but I’m not sure what it is.

Any help will be greatly appreciated.

Chris



Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs