Timing Function

Posted: November 2, 2012 in All Category, Timing Function

<?php

$time = strtotime(‘2012-10-25 16:11:29’);

timingfunction($time).’ ago’;

function timingfunction ($time)
{

$time = time() – $time; // to get the time since that moment

       $tokens = array (
       31536000 => ‘year’,
       2592000 => ‘month’,
       604800 => ‘week’,
       86400 => ‘day’,
       3600 => ‘hour’,
       60 => ‘minute’,
       1 => ‘sec’
           );

          foreach ($tokens as $unit => $text) {
         if ($time < $unit) continue;
        $numberOfUnits = floor($time / $unit);
        return $numberOfUnits.’ ‘.$text.(($numberOfUnits>1)?’s’:”);
        }

}

?>

This Function return as like 1 sec ago, 1 mint ago, 1 hour ago, i week ago………………………

Advertisements

Comments are closed.