public static function human_time_diff($from, $to = null)
    {
        $to = $to ?: time();

        $diff = (int)abs($to - $from);

        if ($diff < self::MINUTE_IN_SECONDS) {
            $since = array($diff, 'sec');
        } elseif ($diff < self::HOUR_IN_SECONDS) {
            $since = array(round($diff / self::MINUTE_IN_SECONDS), 'min');
        } elseif ($diff < self::DAY_IN_SECONDS and $diff >= self::HOUR_IN_SECONDS) {
            $since = array(round($diff / self::HOUR_IN_SECONDS), 'hour');
        } elseif ($diff < self::WEEK_IN_SECONDS and $diff >= self::DAY_IN_SECONDS) {
            $since = array(round($diff / self::DAY_IN_SECONDS), 'day');
        } elseif ($diff < 30 * self::DAY_IN_SECONDS and $diff >= self::WEEK_IN_SECONDS) {
            $since = array(round($diff / self::WEEK_IN_SECONDS), 'week');
        } elseif ($diff < self::YEAR_IN_SECONDS and $diff >= 30 * self::DAY_IN_SECONDS) {
            $since = array(round($diff / (30 * self::DAY_IN_SECONDS)), 'month');
        } elseif ($diff >= self::YEAR_IN_SECONDS) {
            $since = array(round($diff / self::YEAR_IN_SECONDS), 'year');
        }

        if ($since[0] <= 1) {
            $since[0] = 1;
        }

        return $since[0].' '.$since[1].($since[0] == 1 ? '' : 's');
    }
public static function human_time_diff($from, $to = null)
    {
        $to = $to ?: time();

        $diff = (int)abs($to - $from);

        if ($diff < self::MINUTE_IN_SECONDS) {
            $since = array($diff, 'sec');
        } elseif ($diff < self::HOUR_IN_SECONDS) {
            $since = array(round($diff / self::MINUTE_IN_SECONDS), 'min');
        } elseif ($diff < self::DAY_IN_SECONDS and $diff >= self::HOUR_IN_SECONDS) {
            $since = array(round($diff / self::HOUR_IN_SECONDS), 'hour');
        } elseif ($diff < self::WEEK_IN_SECONDS and $diff >= self::DAY_IN_SECONDS) {
            $since = array(round($diff / self::DAY_IN_SECONDS), 'day');
        } elseif ($diff < 30 * self::DAY_IN_SECONDS and $diff >= self::WEEK_IN_SECONDS) {
            $since = array(round($diff / self::WEEK_IN_SECONDS), 'week');
        } elseif ($diff < self::YEAR_IN_SECONDS and $diff >= 30 * self::DAY_IN_SECONDS) {
            $since = array(round($diff / (30 * self::DAY_IN_SECONDS)), 'month');
        } elseif ($diff >= self::YEAR_IN_SECONDS) {
            $since = array(round($diff / self::YEAR_IN_SECONDS), 'year');
        }

        if ($since[0] <= 1) {
            $since[0] = 1;
        }

        return $since[0].' '.$since[1].($since[0] == 1 ? '' : 's');
    }
public static function human_time_diff ( $ from , $ to = null ) { $ to = $ to ? : time ( ) ; $ diff = ( int ) abs ( $ to - $ from ) ; if ( $ diff < self :: MINUTE_IN_SECONDS ) { $ since = array ( $ diff , 'sec' ) ; } elseif ( $ diff < self :: HOUR_IN_SECONDS ) { $ since = array ( round ( $ diff / self :: MINUTE_IN_SECONDS ) , 'min' ) ; } elseif ( $ diff < self :: DAY_IN_SECONDS and $ diff >= self :: HOUR_IN_SECONDS ) { $ since = array ( round ( $ diff / self :: HOUR_IN_SECONDS ) , 'hour' ) ; } elseif ( $ diff < self :: WEEK_IN_SECONDS and $ diff >= self :: DAY_IN_SECONDS ) { $ since = array ( round ( $ diff / self :: DAY_IN_SECONDS ) , 'day' ) ; } elseif ( $ diff < 30 * self :: DAY_IN_SECONDS and $ diff >= self :: WEEK_IN_SECONDS ) { $ since = array ( round ( $ diff / self :: WEEK_IN_SECONDS ) , 'week' ) ; } elseif ( $ diff < self :: YEAR_IN_SECONDS and $ diff >= 30 * self :: DAY_IN_SECONDS ) { $ since = array ( round ( $ diff / ( 30 * self :: DAY_IN_SECONDS ) ) , 'month' ) ; } elseif ( $ diff >= self :: YEAR_IN_SECONDS ) { $ since = array ( round ( $ diff / self :: YEAR_IN_SECONDS ) , 'year' ) ; } if ( $ since [ 0 ] <= 1 ) { $ since [ 0 ] = 1 ; } return $ since [ 0 ] . ' ' . $ since [ 1 ] . ( $ since [ 0 ] == 1 ? '' : 's' ) ; }
Determines the difference between two timestamps.

The difference is returned in a human readable format such as "1 hour",
"5 mins", "2 days".

@param  int    $from Unix timestamp from which the difference begins.
@param  int    $to   Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
@return string Human readable time difference.
Determines the difference between two timestamps .