Last Updated: February 25, 2016
·
665
· yoren

Display time in how long ago format in WordPress

Since Facebook and Twitter became popular, we saw the timestamp of a post like “35 Minutes ago”, “2 Days ago’, “3 Months ago” all the time. In WordPress your could do that by using:

human_time_diff( $from, $to );

For example:

<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#wordpress
Did you know?

WordPress sites collect scripts from themes, plugins, and tag managers. A compromised plugin update can add a skimmer to every page without a change in your own templates.

Security insights from Cside