Get Difference Between 2 Dates Using PHP
Filed Under (General) by Wenbert on 22-10-2007
Tagged Under : PHP, tutorials
Here is how to get the difference between two dates in PHP.
-
-
…
-
$arrayDate=self::toArray($date);
-
return mktime($arrayDate[‘hour’],$arrayDate[‘minute’],$arrayDate[’second’],$arrayDate[‘month’],$arrayDate[‘day’],$arrayDate[‘year’]);
-
}
-
-
$date1=self::toTimestamp($date1);
-
$date2=self::toTimestamp($date2);
-
-
$secs=$date1-$date2;
-
-
case ‘WEEK’:return $secs/60/60/24/7; break;
-
case ‘DAY’:return $secs/60/60/24; break;
-
case ‘HOUR’:return $secs/60/60; break;
-
case ‘MINUTE’:return $secs/60; break;
-
case ‘SECOND’:return $secs; break;
-
default:return $secs/60/60; break;
-
}
-
}
-
…
-
Usage:
-
-
DateFormat::dateDiff($current_tr->requisition_dateTo,$current_tr->requisition_dateFrom,"DAY"));
-
The static function example above is from an MVC Framework. But you can edit it the sample code to fit your needs.
This tutorial is documented here.