[ create a new paste ] login | about

Link: http://codepad.org/HWQrLwBy    [ raw code | output | fork ]

PHP, pasted on Oct 9:
<?php
function convertime($ptime) {
    $etime = time() - $ptime;

    if ($etime < 60) {
        return 'less than minute ag';
    }

    $a = array( 12 * 30 * 24 * 60 * 60  =>  'year',
            30 * 24 * 60 * 60       =>  'month',
            24 * 60 * 60            =>  'day',
            60 * 60                 =>  'hour',
            60                      =>  'minute'
          //  1                       =>  'second'
            );

foreach ($a as $secs => $str) {
    $d = $etime / $secs;
    if ($d >= 1) {
        $r = round($d);
        return $r . ' ' . $str . ($r > 1 ? 's' : '');
    }
}
}

$ctime = strtotime('2009-02-23 10:09:00'); //time from mysql
echo convertime($ctime);

?>


Output:
1
3 years


Create a new paste based on this one


Comments: