In this tutorial you will learn how to PHP date difference in days in a PHP web application.
PHP date difference in days
In this tutorial you will learn how to PHP date difference in days in a PHP web application. The strtotime() function that convert date to time in second .The date difference (in second ) divide by (60 * 60 * 24) that convert into days. The code of "php-date-difference-in-days.php" given below as :
<?php $date1=date('2011-3-1'); $date2=date('2011-1-1'); echo "date1 : ".$date1."<br>"; echo "date2 : ".$date2."<br>"; echo "date difference in-days :: "; $date_diff=strtotime($date1) - strtotime($date2); echo ($date_diff/(60 * 60 * 24))." days"; //( 60 * 60 * 24) // seconds into days ?>
Output :
When run "php-date-difference-in-days.php" display output as :
Download Source Code
[ 0 ] Comments