This just came up on #zftalk, and it appears that the information out there is either incomplete or incorrect, so I thought I’d just put out a simple solution. Here’s a simple way to calculate the difference between two Zend_Date objects (in days):
$jan1 = new Zend_Date('1.12.2009', Zend_Date::DATES);
echo "\nJanuary first: ", $jan1->toString();
$christmas = new Zend_Date('25.12.2009', Zend_Date::DATES);
echo "\nChristmas is on: ", $christmas->toString();
$diff = $christmas->sub($jan1);
echo "\nNumber of days: ", $diff / 60 / 60 / 24;
Additional comments powered by BackType
You can leave a response, or trackback from your own site. Follow any responses to this entry through the RSS 2.0 feed.
Nice and simple. Just thought I’d expand on this. The sub() method returns the milliseconds difference between the receiver and the argument dates, as your example shows, but the method also is a mutator; it changes the value of the receiver date’s unix timestamp to the value that is returned. If this is a problem, you can clone the date before calling sub().