src/ORM/FieldType/DBDate.php
public function TimeDiffIn($format)
    {
        if (!$this->value) {
            return null;
        }

        $now = DBDatetime::now()->getTimestamp();
        $time = $this->getTimestamp();
        $ago = abs($time - $now);
        switch ($format) {
            case "seconds":
                $span = $ago;
                return _t(
                    __CLASS__ . '.SECONDS_SHORT_PLURALS',
                    '{count} sec|{count} secs',
                    ['count' => $span]
                );

            case "minutes":
                $span = round($ago / 60);
                return _t(
                    __CLASS__ . '.MINUTES_SHORT_PLURALS',
                    '{count} min|{count} mins',
                    ['count' => $span]
                );

            case "hours":
                $span = round($ago / 3600);
                return _t(
                    __CLASS__ . '.HOURS_SHORT_PLURALS',
                    '{count} hour|{count} hours',
                    ['count' => $span]
                );

            case "days":
                $span = round($ago / 86400);
                return _t(
                    __CLASS__ . '.DAYS_SHORT_PLURALS',
                    '{count} day|{count} days',
                    ['count' => $span]
                );

            case "months":
                $span = round($ago / 86400 / 30);
                return _t(
                    __CLASS__ . '.MONTHS_SHORT_PLURALS',
                    '{count} month|{count} months',
                    ['count' => $span]
                );

            case "years":
                $span = round($ago / 86400 / 365);
                return _t(
                    __CLASS__ . '.YEARS_SHORT_PLURALS',
                    '{count} year|{count} years',
                    ['count' => $span]
                );

            default:
                throw new \InvalidArgumentException("Invalid format $format");
        }
    }
public function TimeDiffIn($format)
    {
        if (!$this->value) {
            return null;
        }

        $now = DBDatetime::now()->getTimestamp();
        $time = $this->getTimestamp();
        $ago = abs($time - $now);
        switch ($format) {
            case "seconds":
                $span = $ago;
                return _t(
                    __CLASS__ . '.SECONDS_SHORT_PLURALS',
                    '{count} sec|{count} secs',
                    ['count' => $span]
                );

            case "minutes":
                $span = round($ago / 60);
                return _t(
                    __CLASS__ . '.MINUTES_SHORT_PLURALS',
                    '{count} min|{count} mins',
                    ['count' => $span]
                );

            case "hours":
                $span = round($ago / 3600);
                return _t(
                    __CLASS__ . '.HOURS_SHORT_PLURALS',
                    '{count} hour|{count} hours',
                    ['count' => $span]
                );

            case "days":
                $span = round($ago / 86400);
                return _t(
                    __CLASS__ . '.DAYS_SHORT_PLURALS',
                    '{count} day|{count} days',
                    ['count' => $span]
                );

            case "months":
                $span = round($ago / 86400 / 30);
                return _t(
                    __CLASS__ . '.MONTHS_SHORT_PLURALS',
                    '{count} month|{count} months',
                    ['count' => $span]
                );

            case "years":
                $span = round($ago / 86400 / 365);
                return _t(
                    __CLASS__ . '.YEARS_SHORT_PLURALS',
                    '{count} year|{count} years',
                    ['count' => $span]
                );

            default:
                throw new \InvalidArgumentException("Invalid format $format");
        }
    }
public function TimeDiffIn ( $ format ) { if ( ! $ this -> value ) { return null ; } $ now = DBDatetime :: now ( ) -> getTimestamp ( ) ; $ time = $ this -> getTimestamp ( ) ; $ ago = abs ( $ time - $ now ) ; switch ( $ format ) { case "seconds" : $ span = $ ago ; return _t ( __CLASS__ . '.SECONDS_SHORT_PLURALS' , '{count} sec|{count} secs' , [ 'count' => $ span ] ) ; case "minutes" : $ span = round ( $ ago / 60 ) ; return _t ( __CLASS__ . '.MINUTES_SHORT_PLURALS' , '{count} min|{count} mins' , [ 'count' => $ span ] ) ; case "hours" : $ span = round ( $ ago / 3600 ) ; return _t ( __CLASS__ . '.HOURS_SHORT_PLURALS' , '{count} hour|{count} hours' , [ 'count' => $ span ] ) ; case "days" : $ span = round ( $ ago / 86400 ) ; return _t ( __CLASS__ . '.DAYS_SHORT_PLURALS' , '{count} day|{count} days' , [ 'count' => $ span ] ) ; case "months" : $ span = round ( $ ago / 86400 / 30 ) ; return _t ( __CLASS__ . '.MONTHS_SHORT_PLURALS' , '{count} month|{count} months' , [ 'count' => $ span ] ) ; case "years" : $ span = round ( $ ago / 86400 / 365 ) ; return _t ( __CLASS__ . '.YEARS_SHORT_PLURALS' , '{count} year|{count} years' , [ 'count' => $ span ] ) ; default : throw new \ InvalidArgumentException ( "Invalid format $format" ) ; } }
Gets the time difference, but always returns it in a certain format

@param string $format The format, could be one of these:
'seconds', 'minutes', 'hours', 'days', 'months', 'years'.
@return string The resulting formatted period
Gets the time difference but always returns it in a certain format