Calculating difference between Two date
Most of the time in programming we come across finding difference between dates. In PHP we have no direct function to find difference between two dates there are many mode we can find it , one of the simpler method is subtracting the two time stamp and calculating the difference and dividing it by 86400 (60*60*24 = 1 day).
If both the date are timestamp then we can directly calculate it as
<?php
$date1 = 1130120037;
$date2 = time(); /// current time
$diff = $date2 - $date1;
$date_diff = $diff/(60*60*24)
echo $date_diff;
?>
if the dates are in string format then we have to convert it into time stamp using strtotime and
do the above process.
<?php
$date1 =’1-2-2007′;
$date2 = 7-2-2007;
$diff = strtotime($date2) - strtotime($date1);
$date_diff = $diff/(60*60*24)
echo $date_diff;
?>
