Zend_Date – difference between 2 dates

I keep having trouble with this simple calculation! So, here is a little example to get the amount of days between now and the next occurance of July 1st.

//set up the 2 date objects
$now = new Zend_Date();
$next = new Zend_Date();
//we want July 1st
//if we are currently after july this year
if ($now->get(Zend_Date::MONTH) >= 7) {
//we need to work it out til next July
$next->setYear($now->get(Zend_Date::YEAR) + 1);
else {
//this july is fine
$diff = $next->sub($now)->toValue();
return $diff / 60 / 60 / 24;

One comment on “Zend_Date – difference between 2 dates

  1. Rob May 26, 2016 11:23 am

    with me the following worked:

    floor( abs( Zend_Date1->toValue() – Zend_Date2->toValue() ) / 60 / 60 / 24 )

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.