[ create a new paste ] login | about

Link: http://codepad.org/uMAtwmEs    [ 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(
        'year' => 12 * 30 * 24 * 60 * 60,
        'month' => 30 * 24 * 60 * 60,
        'day' => 24 * 60 * 60,
        'hour' => 60 * 60,
        'minute' => 60
    );

    $result = array();

    foreach ($a as $period => $secs) {
        $d = $etime / $secs;

        if ($d >= 0) {
            $result[$period] = floor($d);
            $etime = $etime - ($secs * $result[$period]);
        }
    }

    print_r($result);
}

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

?>


Output:
1
2
3
4
5
6
7
8
Array
(
    [year] => 2
    [month] => 7
    [day] => 27
    [hour] => 15
    [minute] => 34
)


Create a new paste based on this one


Comments: