In this tutorial you will learn how to PHP date difference in months in a PHP web application.
PHP date difference in months
In this tutorial you will learn how to PHP date difference in months 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 $date_diff divide 2628000 that return number of months .The code of "php-date-difference-in-months.php" given below :
<?php $date1=date('2011-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 months => ".floor(($date_diff)/2628000)." months <br>"; ?>
Output :
When run "php-date-difference-in-months.php" display output as :
[ 0 ] Comments