Difference between two dates

In response to a mailing list question, Thomas, the lead developer of the I18n components pointed out that to find the difference between two Zend_Dates, you just have to subtract them:

[php] $date = Zend_Date::now(); $diff = $date->sub($birthdate); $diff->toString(); [/php]

Useful tip, that I’ve put here mainly so that I can find it again when I need it!

Posted by Rob on 27th January 2008 under Tips and Tricks | 4 Comments »

4 Responses to “Difference between two dates”

  1. Ernesto Vargas responded on 08 Jul 2008 at 1:32 am #

    That tip give you the difference as the a whole date but how can you get the different to get the Age for example?

  2. Bede responded on 15 Oct 2008 at 5:16 pm #

    Yes, the date returned doesn’t make much sense on it’s own. How can you extract the number of days or years between the initial dates? I’m going back to the PHP datetime functions ;-(

  3. Jorge responded on 05 Mar 2009 at 9:27 pm #

    Date diff in days?? nothing over the net…. This way isn’t useful…

  4. fg responded on 08 Apr 2009 at 10:42 pm #

    can you write more usable example how to get diff in days and hours?