Skip to content

Instantly share code, notes, and snippets.

<?php
// This function will return "now", "3 seconds ago", "1 month ago" etc ...
// example: echo 'posted ' . get_the_relative_time(mktime(date("H"), date("i"), date("s"), date("m")-1, date("d"), date("Y")));
function get_the_relative_time($time = null, $now = 20) {
if(is_null($time)) $time = date('U');
$time_diff = date("U") - $time; // difference in seconds
$second = 1;