Created
July 8, 2013 07:23
-
-
Save ludwigmair/5946834 to your computer and use it in GitHub Desktop.
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 | |
// >= 5.4 | |
$date1 = new DateTime('2013-02-05'); | |
$date2 = new DateTime('2013-03-05'); | |
$interval = $date1->diff($date2); | |
// Suppose you only want to display the days | |
printf("difference %d days <br>",$interval->days); | |
// bis 5.3 | |
$date1 = '2013-02-05'; | |
$date2 = '2013-03-05'; | |
$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)); | |
printf(" %d days<br>", $days); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment