Converting created_at to the number of days ago format

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

@seconds_from_model_creation = (Time.now.to_i - Time.at
(@model.created_at).to_i)
@days_from_creation = @seconds_from_model_creation / (606024)

On May 12, 6:48 pm, Charanya N. <rails-mailing-l…@andreas-

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.

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 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