WordPress Snippets at WPcustoms

Relative date posted x days ago

We require two functions for comments and posts. Each display a relative date and instead of ‘posted on 12/04/2014’ it shows: ‘x weeks ago’


/**
 * Snippet Name: Relative date posted x days ago
 * Snippet URL: http://www.wpcustoms.net/snippets/relative-date-posted-x-days-ago/
 */
 function wpc_posts_relative_date () {
echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';
}

function wpc_comments_relative_date () {
echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago';
}