Skip to content

Instantly share code, notes, and snippets.

@ishahid
Created January 15, 2014 02:16
Show Gist options
  • Save ishahid/8429640 to your computer and use it in GitHub Desktop.
Save ishahid/8429640 to your computer and use it in GitHub Desktop.
Find difference between two dates in days. PHP 5.2.x.
<?php
/**
* Find difference between two dates in days. PHP 5.2.x.
*/
$d1 = date('Y-m-d', strtotime('2013-06-13 12:27:43'));
$d2 = date("Y-m-d");
echo diff($d1, $d2);
function diff($date1, $date2) {
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24) / (60*60*24));
return $days;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment