Forum: Ruby on Rails converting created_at to the number of days ago format

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Charanya N. (Guest)
on 2009-05-12 15:48
Hi

I want to display the created_at field of my model in the format n days
ago n hours ago

Please help me in this
Vladimir R. (Guest)
on 2009-05-12 16:38
(Received via mailing list)
@seconds_from_model_creation = (Time.now.to_i - Time.at
(@model.created_at).to_i)
@days_from_creation = @seconds_from_model_creation / (60*60*24)
...

On May 12, 6:48 pm, Charanya N. <rails-mailing-l...@andreas-
Vladimir R. (Guest)
on 2009-05-12 16:50
(Received via mailing list)
Sorry, that should be
(Time.now.to_i - Time.at(@model.created_at.to_i).to_i)

and there are questions about timezones and stuff. You need to watch
it carefully.
Charanya N. (Guest)
on 2009-05-14 08:44
Vladimir R. wrote:
> Sorry, that should be
> (Time.now.to_i - Time.at(@model.created_at.to_i).to_i)
>
> and there are questions about timezones and stuff. You need to watch
> it carefully.

Thank you Vladimir
This topic is locked and can not be replied to.