Hello Readers
If you want to calculate difference between two dates using PHP , use below code.
comment: Suppose we have the two dates below date1 and date2
$date1 = "2014-06-11";
$date2 = "2015-07-16";
comment:then we get diffrence with absolute value
$diff = abs(strtotime($date2) - strtotime($date1));
comment:then use the floor() function rounds a number DOWN to the nearest integer
$years = floor($diff / (365606024));
$months = floor(($diff - $years * 365606024) / (30606024));
$days = floor(($diff - $years * 365606024 - $months30606024)/ (60*60*24));
echo $years.'year'.$months.'month'.$days.'days';
0 Comment(s)