public static function diffAsText($datetime1, $datetime2, $absolute = false)
    {
        if (!($datetime1 instanceof \DateTimeInterface)) {
            $datetime1 = new static($datetime1);
        }
        if (!($datetime2 instanceof \DateTimeInterface)) {
            $datetime2 = new static($datetime2);
        }

        $interval = $datetime1->diff($datetime2, $absolute);
        $str = '';
        $str .= $interval->y ? $interval->y . ' year. ' : '';
        $str .= $interval->m ? $interval->m . ' mon. ' : '';
        $str .= $interval->d ? $interval->d . ' day. ' : '';
        $str .= $interval->h ? $interval->h . ' hour. ' : '';
        $str .= $interval->i ? $interval->i . ' min. ' : '';
        $str .= $interval->s || $str === '' ? $interval->s . ' sec. ' : '';

        return rtrim($str);
    }
public static function diffAsText($datetime1, $datetime2, $absolute = false)
    {
        if (!($datetime1 instanceof \DateTimeInterface)) {
            $datetime1 = new static($datetime1);
        }
        if (!($datetime2 instanceof \DateTimeInterface)) {
            $datetime2 = new static($datetime2);
        }

        $interval = $datetime1->diff($datetime2, $absolute);
        $str = '';
        $str .= $interval->y ? $interval->y . ' year. ' : '';
        $str .= $interval->m ? $interval->m . ' mon. ' : '';
        $str .= $interval->d ? $interval->d . ' day. ' : '';
        $str .= $interval->h ? $interval->h . ' hour. ' : '';
        $str .= $interval->i ? $interval->i . ' min. ' : '';
        $str .= $interval->s || $str === '' ? $interval->s . ' sec. ' : '';

        return rtrim($str);
    }
public static function diffAsText ( $ datetime1 , $ datetime2 , $ absolute = false ) { if ( ! ( $ datetime1 instanceof \ DateTimeInterface ) ) { $ datetime1 = new static ( $ datetime1 ) ; } if ( ! ( $ datetime2 instanceof \ DateTimeInterface ) ) { $ datetime2 = new static ( $ datetime2 ) ; } $ interval = $ datetime1 -> diff ( $ datetime2 , $ absolute ) ; $ str = '' ; $ str .= $ interval -> y ? $ interval -> y . ' year. ' : '' ; $ str .= $ interval -> m ? $ interval -> m . ' mon. ' : '' ; $ str .= $ interval -> d ? $ interval -> d . ' day. ' : '' ; $ str .= $ interval -> h ? $ interval -> h . ' hour. ' : '' ; $ str .= $ interval -> i ? $ interval -> i . ' min. ' : '' ; $ str .= $ interval -> s || $ str === '' ? $ interval -> s . ' sec. ' : '' ; return rtrim ( $ str ) ; }
Calculates a difference between two dates
@see http://www.php.net/manual/en/datetime.diff.php
@param  integer|string|\DateTimeInterface $datetime1
@param  integer|string|\DateTimeInterface $datetime2
@param  boolean $absolute
@return string Something like this: 1 year. 2 mon. 6 day. 4 hours. 21 min. 10 sec.
Calculates a difference between two dates