Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i create a human readable datediff in Rails

I have a timestamp that represents the last time a particular record was viewed. I want to present to the user a display that gives a human readable representation of the difference between that time and now.

So it should be something like

"Last viewed 38 seconds ago"

or "Last viewed 1 hour 15 minutes 10 seconds ago"

Is there a quick way to do this in rails?

like image 793
JoshReedSchramm Avatar asked Feb 27 '23 10:02

JoshReedSchramm


1 Answers

distance_of_time_in_words, or dotiw (allegedly better)

like image 153
Chubas Avatar answered Mar 10 '23 21:03

Chubas