Created
January 15, 2014 02:16
-
-
Save ishahid/8429640 to your computer and use it in GitHub Desktop.
Find difference between two dates in days. PHP 5.2.x.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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