I have the below line of codes
$day1 = new Zend_Date('2010-03-01', 'YYYY-mm-dd');
$day2 = new Zend_Date('2010-03-05', 'YYYY-mm-dd');
$dateDiff = $day2->getDate()->get(Zend_Date::TIMESTAMP) - $day1->getDate()->get(Zend_Date::TIMESTAMP);
$days = floor((($dateDiff / 60) / 60) / 24);
return $days;
this will return 4
But if gave
$day1 = new Zend_Date('2010-02-28', 'YYYY-mm-dd');
$day2 = new Zend_Date('2010-03-01', 'YYYY-mm-dd');
$dateDiff = $day2->getDate()->get(Zend_Date::TIMESTAMP) - $day1->getDate()->get(Zend_Date::TIMESTAMP);
$days = floor((($dateDiff / 60) / 60) / 24);
return $days;
it will return -27 .. how will i get right answer
return $days;
this gives the right answer
number of days between date of registration (later) and date of purchase (before)
If $date is a Zend_Date object you can use the following:
or the other subXxx functions of the Zend_Date object.
I believe the problem is in your part string. Try YYYY-MM-dd instead.
I've extended
Zend_Date
for my own convenience functions. My solution is similar to Nisanth's, with some key differences:round()
instead ofceil()
1
to the resultExample code: