0

I have 2 Zend_Date objects:

$d1 = new Zend_Date('2011-11-14 12:20:30');
$d2 = new Zend_Date('2012-11-16 13:40:10');

And I need to calculate difference. My output should be like this:

Years: 1, Months: 0, Days: 2, Hours: 1, Minutes: 19, Seconds: 40

I can do it with DateTime class and diff method. But my hoster has PHP version < 5.3. Can you help me how can I do it in Zend? Thanks.

Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
  • possible duplicate of [how to calculate a difference between two Zend_Date objects, in months](http://stackoverflow.com/questions/3032101/how-to-calculate-a-difference-between-two-zend-date-objects-in-months) – Gordon Oct 28 '11 at 08:59
  • http://stackoverflow.com/questions/2513830/zend-date-day-difference – xdazz Oct 28 '11 at 09:00

2 Answers2

0

There is no implemented function to calculate the difference between two dates, unfortunately.

<?php
$diff = $d2->sub($d1)->toValue();
$days = floor($diff/60/60/24);
$months = floor($diff/60/60/24/30);
?>

This should help you get the variables you need.

Tom
  • 1,647
  • 11
  • 24
-3

You can get the timestamp of Zend_Date objects by $date->get(Zend_Date::TIMESTAMP). Then you can work with the normal PHP-functions to format your date like described in the PHP manual

dwalldorf
  • 1,379
  • 3
  • 12
  • 21