ExpressiveDate::getDifferenceInYears PHP Method

getDifferenceInYears() public method

Get the difference in years.
public getDifferenceInYears ( ExpressiveDate $compare = null ) : string
$compare ExpressiveDate
return string
    public function getDifferenceInYears($compare = null)
    {
        if (!$compare) {
            $compare = new ExpressiveDate(null, $this->getTimezone());
        }
        return $this->diff($compare)->format('%r%y');
    }

Usage Example

Beispiel #1
0
 public function testGetDateDifferenceInYears()
 {
     $past = new ExpressiveDate('January 2010');
     $future = new ExpressiveDate('January 2013');
     $this->assertEquals(-3, $future->getDifferenceInYears($past));
     $this->assertEquals(3, $past->getDifferenceInYears($future));
 }