PHP Function Calculate difference between two dates
April 18th, 2008 | posted by Anonymous
in
This PHP function calculate difference between two dates. The result in array format contain day, hour, minute and second.
<?php function dateDiff($date1, $date2) { $s = strtotime($date2) - strtotime($date1); $d = intval($s/86400); $s -= $d*86400; $h = intval($s/3600); $s -= $h*3600; $m = intval($s/60); $s -= $m*60; return array("d"=>$d, "h"=>$h, "m"=>$m, "s"=>$s); } ?>
Usage :
<?php print_r(dateDiff("2004-02-25 13:24:00", "2004-03-03 21:52:03")); ?>
Output :
Array ( [d] => 7 [h] => 8 [m] => 28 [s] => 3 )











Post new comment