Difference in days between two dates [PHP]
Problem
You have two dates and you want to know the difference between them in days.
Solution
$datetime1 = new DateTime('20110107');
# ... = new DateTime('2011-01-07'); is also good format
$datetime2 = new DateTime('20110110');
$interval = $datetime1->diff($datetime2);
print $interval->days; # 3
Check out the DateTime class, DateTime::diff, and the DateInterval class.
Credits
I found this elegant solution in this thread.
Homework
How old are you (in days)?
Comments (0)
Trackbacks (0)
Leave a comment
Trackback