Date formatting with moment().fromNow() option


#1

I’d like to display recent posts with date formatted as “3 days ago”. I understand that moments.js supports that, but how can I do that?

Here is the code for the part where the date is displayed in sidebar widget:

`<time class='c-teaser__date' datetime='{{ date format='YYYY-MM-DD' }}' title='{{ date format='DD MMMM YYYY' }}'>{{ date format='DD.MM.YYYY.' }}</time>`

Thanks!


#2

The date helper supports the timeago option :slight_smile:


#3

Or you may try this method called fromNow() -
I am using it like this - const theDateIwant = moment(myDate).fromNow();