Display Date As Time Passed / Time Ago (e.g. 5 mins ago)

Thank you very much for your sharing!!

1 Like

yes, it worked! thanks

Firstly, it did not. But then I realized that my date format was set to eg. Feb 22 and it was counting something like 22 years ago (similar to what juragan had above). Then I changed to 2/22/2022 and it works perfectly.

I only noticed that when the published date is today, it counts the hours from midnight. For example, I just posted an entry (it’s 20:50 now, or 8:50 pm) and it shows “posted 21h ago”. It’s not that big of an issue though. Should be fine for my MVP now.

Maybe I’ll look into having for the entries that were posted today display “today” or “new” and for yesterday’s posts “yesterday” soon (and the rest as it is now). Suggestions welcome :slight_smile:

EDIT
I changed the format in my collection settings and included hours now too. Then I changed the format of displaying on the site to show that change, and now the code counts the hours accurately (not from midnight as stated above).

@hiddenoctave Replied via DM

1 Like

Hey, sorry to bother you.

I really can’t seem to get this to work. I’m not sure if I’m doing something silly, as I’m new(ish) to Webflow.

Here’s what I’ve tried:

  1. Adding the custom code into the Before Body section of page settings.
  2. Setting the date created format to 4/20/2023

However nothing changes to my date.

Any ideas of what it could be, or is there something that I am missing? :slight_smile:

I must have been tired that night, because I just took a quick scan over the code and realized I didn’t add the “post-date” class to my date.

All solved and working now! Thank you for the code!

Seconds
Why is it showing like this?