PHP date difference in days

PHP date difference in days


Posted in : PHP Posted on : January 22, 2011 at 6:39 PM Comments : [ 0 ]

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
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics