Convert a Date / Timestamp to Time Ago for Posts

Displaying an exact date on your posts is great, but why not change things up just a little and display "1 Hour Ago", "2 Hours Ago", "1 Day Ago", "2 Days Ago", "1 Week Ago", etc. Just add this snippet to your single.php file, index.php file, or any other template within the loop, and you are good to go.

echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';

Comments  Leave a Reply

  1. maybe you should start thinking about internationalising your snippets, we’re living in the 21st century after all…

    1. Lots of things I would like to add to the site, however only so much time in a day. This is a good idea though, thanks.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!