Return to Snippet

Revision: 59986
at October 13, 2012 09:54 by mburica


Initial Code
$time = time() - $time;
        
        $points = array(
            'year'     => 31556926,
            'month'    => 2629743,
            'week'     => 604800,
            'day'      => 86400,
            'hour'     => 3600,
            'minute'   => 60,
            'second'   => 1
        );
        
        foreach($points as $point => $value)
        {
            if($elapsed = floor($time/$value) > 0)
            {
                $s = $elapsed>1?'s':'';
                $timestamp = "$elapsed $point$s";
                break;
            }
        }

Initial URL


Initial Description
Takes a # of seconds and converts it to human readable format.
If happened within seconds-years.

Initial Title
Seconds to human readable time

Initial Tags
php

Initial Language
PHP