phpdate

Operation with dates with format ISO 8601?


I need to make an PHP operation with dates with format ISO 8601. Something like:

$starDate = 2012-03-20T00:00:00+01:00; //20 March 2012
$endDate = 2012-04-01T00:00:00+02:00; // 1 April 2012

$diff = $starDate - $endDate; //Result should be: 13

Using this code $diff get a value of cero.


Solution

  • Try this :

    function date_diff($date1, $date2)  
    { 
     $s = strtotime($date2)-strtotime($date1); 
     $d = intval($s/86400)+1;   
     return "$d"; 
    }
    

    Source : http://forum.hardware.fr/hfr/Programmation/PHP/php-calculer-nombre-sujet_30415_1.htm