How to know PHP version ?
Here is an example of knowing the difference in two dates , the first date is taken as present date and past date is created by using date object.
<?Php
date_default_timezone_set ("Asia/Kolkata");
$date1=new DateTime("now") ;
echo $date1->format('d-m-y H:i:s');
echo "<br><br>";
$date2=new DateTime("1976-5-5");
$date= $date1->diff($date2);
echo $date->format('%y Years, %m Months, %d Days');
?>
The output is here
05-03-12 19:17:19
35 Years, 10 Months, 0 Days
$date1=new DateTime('2016-03-30');
$date2=new DateTime('2015-01-29');
$difference=$date1->diff($date2);
echo " Difference is $difference->y years, $difference->m Months & $difference->d Days ";
Output is here
Difference is 1 years, 2 Months & 1 Days
DEMO of showing difference in date and time
$date1=strtotime('2016-03-30');
$date2=strtotime('2015-01-29');
$difference=$date1-$date2;
echo " Difference in Seconds $difference ";
Output is here
Difference in Seconds 36806400
Data in seconds can be converted meaningful output by calculating days months etc.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.