You tried to calculate days manually but you did not thought of DST.
Simply use the difference as input for a new date

$days = $date2->subDate($date1)->get(Zend_Date::DAY_OF_YEAR) - 1;

Simple maths :-)
PS: Does not work for dates which differ more than a year.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "David Mintz" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, October 20, 2008 11:27 PM
Subject: [fw-general] Zend_Date arithmetic: difference in days (not seconds) between two dates


I would like to compute the difference in days between two dates. I have the
fix_dst option set to true and the timezone is America/New York. A DST
change happened in my timezone on March 9, 2008. So,

$date1 = new Zend_Date(array(
    'year'=> 2008,
   'month'=>3,
   'day'=>7,
   'hour'=>12,
));

$date2 = new Zend_Date(array(
   'year'=> 2008,
    'month'=>3,
   'day'=>10,
   'hour'=>12,
));

$diff = $date2->sub($date1);
print " difference in days is ".$diff/86400;

And the output is not what I want to hear, i.e., not 3 but 2.9583333333333

I think I understand, Zend_Date is telling me how many seconds actually
elapsed between the two dates. But I want to figure out the days, accounting for the fact that one of the intervening days had only 23 hours. What's the
correct approach?

Thanks.

--
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


Reply via email to