Possible Duplicate:
Date Difference in php?
Compare 2 timestamps in PHP and get the days between?
I've 2 dates like 15/02/2012
and 18/03/2012
, I need to know the number of days difference between them. Does such a utility exist in php?
Possible Duplicate:
Date Difference in php?
Compare 2 timestamps in PHP and get the days between?
I've 2 dates like 15/02/2012
and 18/03/2012
, I need to know the number of days difference between them. Does such a utility exist in php?
$diff = (int) ( abs(strtotime($date1) - strtotime($date2)) / (60 * 60 * 24) );
echo 'diff:' . $diff
PHP has a function for this:
http://www.php.net/manual/en/datetime.diff.php
Example
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
Output
+2 days
You could turn those dates into timestamps:
$ts1 = strtotime("15-02-2012");
$ts2 = strtotime("18-03-2012");
$diff = ($ts2 - $ts1)/86400;
echo $diff . " days";