Jump to content

Help my Date function i almost got it.


Gayner

Recommended Posts

function time_elapsed_string($ptime) {
    $etime = time() - $ptime;
    
    if ($etime < 1) {
        return '0 seconds';
    }
    
    $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 ago' : '');
        }
    }
}

 

 

 

Everything works fine.. I get 25, seconds ago bla bla.

 

 

But when It get's into minutes.. it only does 4 Minutes ago.

 

I want it to be, 4Minutes 28Seconds ago.

 

Or whatever.

 

Sorry but this is the farthest i gotten in php code now i need ur help thanks.

Link to comment
https://forums.phpfreaks.com/topic/181702-help-my-date-function-i-almost-got-it/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.