Monday, March 24, 2014

PHP Code To Calculate The Difference Between Two Dates

This function can calculate the difference between two dates. Here the code:
function diff($firstDate,$secondDate){
   $first=explode("-",$firstDate);
   $second=explode("-",$secondDate);
   $first = @GregorianToJD($first[1], $first[2], $first[0]);
   $second = @GregorianToJD($second[1], $second[2], $second[0]);
   $diff = $second - $first;
return $diff;
}

echo diff("2014-02-25","2014-02-28"); // output is 3
Good Luck !!!

0 comments:

Post a Comment