src/util/Date.php
public static function span($remote, $local = null, $output = 'years,months,weeks,days,hours,minutes,seconds') {
        // Normalize output
        $output = trim(strtolower((string)$output));

        if (!$output) {
            // Invalid output
            return false;
        }

        // Array with the output formats
        $output = preg_split('/[^a-z]+/', $output);

        // Convert the list of outputs to an associative array
        $output = array_combine($output, array_fill(0, count($output), 0));

        // Make the output values into keys
        extract(array_flip($output), EXTR_SKIP);

        if ($local === null) {
            // Calculate the span from the current time
            $local = time();
        }

        // Calculate timespan (seconds)
        $timespan = abs($remote - $local);

        if (isset($output['years'])) {
            $timespan -= static::YEAR * ($output['years'] = (int)floor($timespan / static::YEAR));
        }

        if (isset($output['months'])) {
            $timespan -= static::MONTH * ($output['months'] = (int)floor($timespan / static::MONTH));
        }

        if (isset($output['weeks'])) {
            $timespan -= static::WEEK * ($output['weeks'] = (int)floor($timespan / static::WEEK));
        }

        if (isset($output['days'])) {
            $timespan -= static::DAY * ($output['days'] = (int)floor($timespan / static::DAY));
        }

        if (isset($output['hours'])) {
            $timespan -= static::HOUR * ($output['hours'] = (int)floor($timespan / static::HOUR));
        }

        if (isset($output['minutes'])) {
            $timespan -= static::MINUTE * ($output['minutes'] = (int)floor($timespan / static::MINUTE));
        }

        // Seconds ago, 1
        if (isset($output['seconds'])) {
            $output['seconds'] = $timespan;
        }

        if (count($output) === 1) {
            // Only a single output was requested, return it
            return array_pop($output);
        }

        // Return array
        return $output;
    }
public static function span($remote, $local = null, $output = 'years,months,weeks,days,hours,minutes,seconds') {
        // Normalize output
        $output = trim(strtolower((string)$output));

        if (!$output) {
            // Invalid output
            return false;
        }

        // Array with the output formats
        $output = preg_split('/[^a-z]+/', $output);

        // Convert the list of outputs to an associative array
        $output = array_combine($output, array_fill(0, count($output), 0));

        // Make the output values into keys
        extract(array_flip($output), EXTR_SKIP);

        if ($local === null) {
            // Calculate the span from the current time
            $local = time();
        }

        // Calculate timespan (seconds)
        $timespan = abs($remote - $local);

        if (isset($output['years'])) {
            $timespan -= static::YEAR * ($output['years'] = (int)floor($timespan / static::YEAR));
        }

        if (isset($output['months'])) {
            $timespan -= static::MONTH * ($output['months'] = (int)floor($timespan / static::MONTH));
        }

        if (isset($output['weeks'])) {
            $timespan -= static::WEEK * ($output['weeks'] = (int)floor($timespan / static::WEEK));
        }

        if (isset($output['days'])) {
            $timespan -= static::DAY * ($output['days'] = (int)floor($timespan / static::DAY));
        }

        if (isset($output['hours'])) {
            $timespan -= static::HOUR * ($output['hours'] = (int)floor($timespan / static::HOUR));
        }

        if (isset($output['minutes'])) {
            $timespan -= static::MINUTE * ($output['minutes'] = (int)floor($timespan / static::MINUTE));
        }

        // Seconds ago, 1
        if (isset($output['seconds'])) {
            $output['seconds'] = $timespan;
        }

        if (count($output) === 1) {
            // Only a single output was requested, return it
            return array_pop($output);
        }

        // Return array
        return $output;
    }
Returns time difference between two timestamps, in human readable format.
If the second timestamp is not given, the current time will be used.
Also consider using [Date::fuzzy_span] when displaying a span.

$span = Date::span(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2)
$span = Date::span(60, 182, 'minutes'); // 2

@param   integer $remote timestamp to find the span of
@param   integer $local timestamp to use as the baseline
@param   string $output formatting string
@return  string   when only a single output is requested
@return  array    associative list of all outputs requested