I am wondering if it's possible to get amount of months in rails from response.
If my data contains published.at: '2020-12-31 08:00:00 UTC'
.
How can I render in my html Published: 3 months ago
instead of displaying the entire date?
Now I display it as <%= item.published_at %>
Asked
Active
Viewed 28 times
1

Dave
- 1
- 1
- 9
- 38
-
Does this have a decent answer: https://stackoverflow.com/questions/9428605/find-number-of-months-between-two-dates-in-ruby-on-rails – Ben Stephens Mar 25 '21 at 20:33
-
@BenStephens need this to be done in html only – Dave Mar 25 '21 at 20:37
-
I'm not sure I understand, it's in ERB isn't it? If yes, you should be able to put ruby code in there. – Ben Stephens Mar 25 '21 at 20:41
1 Answers
0
You can use time_ago_in_words
Published <%= time_ago_in_words(item.published_at) %> ago

razvans
- 3,172
- 7
- 22
- 30