Convert a date into a string this tells how long ago That's date was ... eg:2 days ago, 3 minutes ago. Function ago ($d) { $c = getdate (); $p = Array (' Year ', ' mon ', ' mday ', ' hours ', ' minutes ', ' seconds '); $display = Array (' Year ', ' Month ', ' Day ', ' hour ', ' minute ', ' second '); $factor = Array (0, 12, 30, 24, 60, 60); $d = Datetoarr ($d); for ($w = 0; $w < 6; $w + +) { if ($w > 0) { $c [$p [$w]] + = $c [$p [$w-1]] * $factor [$w]; $d [$p [$w]] + = $d [$p [$w-1]] * $factor [$w]; } if ($c [$p [$w]]-$d [$p [$w]] > 1) { Return ($c [$p [$w]]-$d [$p [$w]]. ' '. $display [$w]. ' S ago '; } } Return '; } You can replace this if need is. This converts my dates returned from a MySQL date string into a array object similar to this returned by GETDATE (). function Datetoarr ($d) { Preg_match ("/([0-9]{4}) (\\-) ([0-9]{2}) (\\-) ([0-9]{2}) ([0-9]{2}) (\ \:) ([0-9]{2}) (\ \:) ([0-9]{2})/", $d, $matches); Return Array ( ' Seconds ' = $matches [10], ' Minutes ' = $matches [8], ' Hours ' = $matches [6], ' Mday ' = $matches [5], ' Mon ' = $matches [3], ' Year ' = $matches [1], ); } |