About Chris Morrell

I am a Philadelphia web designer and developer who focuses on PHP development and usable design. I am also the Director of IT for the International Association of Certified Home Inspectors.

Please Note: My site fell victim to a Wordpress security flaw a few weeks ago, and I'm just getting everything back to normal. Please bear with me.

I am currently not accepting any new clients.

Other Sites/Clients

Contact Me

If you need to get in touch with me, my name is Chris and my domain name is cmorrell.com. Think about it.

Calculating the difference in days between two Zend_Date objects

Posted by Chris Morrell on November 18th, 2009 in Web Development, Zend Framework (tagged , , )

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;

1 Comment »

One Response to “Calculating the difference in days between two Zend_Date objects”

  1. Michael Hodgins

    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().

Leave a Reply

Additional comments powered by BackType

Comments & Trackbacks

You can leave a response, or trackback from your own site. Follow any responses to this entry through the RSS 2.0 feed.

More...

@inxilpro

  • Developing PHP applications that use a payment gateway (Authorize.net/PayPal/etc)? I'd love you feedback on a project… DM for details. 3 hrs ago
  • Loving the camel case matching in Zend Studio's code assist. "new ZDbAA" + TAB = "new Zend_Db_Adapter_Abstract" 1 day ago
  • Just got home after running 10 miles. I don't think my legs work anymore. Jesus. 3 days ago
  • More updates...
Copyright © Chris Morrell, Powered by WordPress, Entry RSS Feed / Comment RSS Feed