In this tutorial you will learn how to find PHP date difference in years in a PHP web application.
PHP date difference in years
In this tutorial you will learn how to find PHP date difference in years in a PHP web application. In this tutorial $date1 and $date2 variable that use for assign date and $date_diff use for assign difference of dates in Unix timestamp (in second) . The " floor(($date_diff)/(60*60*24*365)) " that return number of years. The code of "php-date-difference-in-years.php" given below as :
<?php
$date1=date('2004-1-1');
$date2=date('2011-5-2');
echo "date1 :: ".$date1."<br>";
echo "date2 :: ".$date2."<br>";
$date_diff=strtotime($date2)-strtotime($date1);
echo " date difference in years => ".floor(($date_diff)/(60*60*24*365)) ." years <br>";
?>
Output :
When run "php-date-difference-in-years.php" display output as :


[ 0 ] Comments