0

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.

JPashs
  • 13,044
  • 10
  • 42
  • 65
  • duplicate ? http://stackoverflow.com/questions/5988450/difference-between-2-dates-in-seconds and http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php – ChapMic Mar 13 '12 at 19:50

1 Answers1

0

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

Julien
  • 3,509
  • 20
  • 35